Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
!fix: Regex/glob error
Browse files Browse the repository at this point in the history
!Some snippets downloaded need to be re-add after this update
  • Loading branch information
Mara-Li committed Apr 23, 2022
1 parent 0626e9a commit 6deeb1b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
17 changes: 14 additions & 3 deletions Snippet-downloader/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,19 @@ export class SnippetDownloaderTabs extends PluginSettingTab {
containerEl.empty();

containerEl.createEl('h2', {text: 'Snippet Manager Settings'});

const desc_excluder = document.createDocumentFragment();
desc_excluder.createEl('span', null, (span)=>{
span.innerText='Type the snippet name you want to exclude from the list, without the extension.\nYou can also use regex, for example: ';
span.createEl('code', {text: '^(.*)$'});
span.createEl('span', {text:' will match all snippets.\n\n'});
span.createEl('a', null, (link)=>{
link.innerText='You can check your regex here.';
link.href='https://regex101.com/';
})
})
new Setting(containerEl)
.setName('Excluded Snippet')
.setDesc('Type the snippet name you want to exclude from the list, without the extension. Glob and regex can work. Separate by comma.')
.setDesc(desc_excluder)
.addTextArea(text => text
.setPlaceholder('BadCSS I hate, badCSS*')
.setValue(this.plugin.settings.excludedSnippet)
Expand All @@ -62,7 +71,9 @@ export class SnippetDownloaderTabs extends PluginSettingTab {
containerEl.createEl("p");
containerEl.createEl("span")
.createEl("b", { text: "Note: " })
containerEl.createSpan({ text: "This does not delete the linked snippet, this should be done from your .obsidian/snippet folder." });
containerEl.createEl("span",{ text: "This does not delete the linked snippet, this should be done from your " });
containerEl.createEl("code", { text: ".obsidian/snippets" }).setAttribute("style", "font-family: var(--font-monospace)");
containerEl.createSpan({ text: " folder" });

for (const repoPath of this.plugin.settings.snippetList) {
const repoName = repoPath.repo.replace('https://github.com/','')
Expand Down
11 changes: 2 additions & 9 deletions Snippet-downloader/utils.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
import globRegex from 'glob-regex';

export function searchExcluded(excludedSnippet: string, name: string): boolean {
if (excludedSnippet.length < 1) {
return false;
}
const excluded = excludedSnippet.split(",").map(e => {return e.trim();}).filter(x=>x.length>0)
const excluded = excludedSnippet.split(",").map(e => {return e.trim();}).filter(x=>x.length>0)
for (const excl of excluded){
if (excl === name.replace('.css', '').trim()){
return true;
}
const regExcl = globRegex(excl);
if (name.match(regExcl)){
if (name.match(new RegExp(excl))){
return true;
}
const regPureExcl= new RegExp(excl)
if (name.match(regPureExcl)) {
return true;
}
}
return false;
}
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"dependencies": {
"@octokit/core": "^3.6.0",
"glob-regex": "^0.3.2",
"js-base64": "^3.7.2",
"standard-version": "^9.3.2"
}
Expand Down

0 comments on commit 6deeb1b

Please sign in to comment.