diff --git a/src/bbt/helpers.ts b/src/bbt/helpers.ts index 774aa7e..ac8ee6a 100644 --- a/src/bbt/helpers.ts +++ b/src/bbt/helpers.ts @@ -23,14 +23,11 @@ export async function mkMDDir(mdPath: string) { await app.vault.createFolder(dir); } -const toSpaceRegEx = /\s*[*?]+\s*/g; -const toDashRegEx = /\s*[:"<>|]+\s*/g; - export function replaceIllegalChars(str: string) { return str - .replace(toSpaceRegEx, ' ') + .replace(/\s*[*?]+\s*/g, ' ') .trim() - .replace(toDashRegEx, ' - ') + .replace(/\s*[:"<>|]+\s*/g, ' - ') .trim(); } diff --git a/src/bbt/template.env.ts b/src/bbt/template.env.ts index 4ff1039..38c2ae1 100644 --- a/src/bbt/template.env.ts +++ b/src/bbt/template.env.ts @@ -182,18 +182,16 @@ export class PersistExtension implements Extension { ); } - static re = /%% begin (.+?) %%([\w\W]*?)%% end \1 %%/gi; static hasPersist(str: string) { - this.re.lastIndex = 0; - return this.re.test(str); + return /%% begin (.+?) %%([\w\W]*?)%% end \1 %%/gi.test(str); } static prepareTemplateData(templateData: T, md: string): T & WithRetained { const out: Record = {}; if (!md) return templateData; - this.re.lastIndex = 0; - for (const match of md.matchAll(this.re)) { + const matches = md.matchAll(/%% begin (.+?) %%([\w\W]*?)%% end \1 %%/gi); + for (const match of matches) { out[match[1]] = match[2]; } @@ -208,21 +206,19 @@ export class ObsidianMarkdownLoader extends Loader { sourceFile: string; async = true; - wikiLinkRe = /^\[\[([^\]]+)\]\]$/; - markdownLinkRe = /^\[[^\]]*\]\(([^)]+)\)$/; setSourceFile(path: string) { this.sourceFile = path; } getLinkPath(link: string) { - let match = link.trim().match(this.wikiLinkRe); + let match = link.trim().match(/^\[\[([^\]]+)\]\]$/); if (match) { return match[1]; } - match = link.trim().match(this.markdownLinkRe); + match = link.trim().match(/^\[[^\]]*\]\(([^)]+)\)$/); if (match) { return match[1];