fixed note name being included before frontmatter

This commit is contained in:
Ell 2023-10-26 11:55:17 +02:00
parent 6537a84562
commit b1370b772e
3 changed files with 12 additions and 9 deletions

View file

@ -227,15 +227,22 @@ export default class JustSharePleasePlugin extends Plugin {
let text = await this.app.vault.cachedRead(file);
// strip frontmatter
let frontmatter = /^(---\s*\n.*?\n---)\s*\n(.*)$/s;
if (this.settings.stripFrontmatter)
text = text.replace(/^---\s*\n.*?\n---\s*\n(.*)$/s, "$1");
text = text.replace(frontmatter, "$2");
// strip comments
text = text.replace(/%%.*?%%/sg, "");
// include note name
if (this.settings.includeNoteName)
text = `# ${file.basename}\n\n${text}`;
// include note name (after frontmatter!)
if (this.settings.includeNoteName) {
let title = `# ${file.basename}\n\n`;
if (frontmatter.test(text)) {
text = text.replace(frontmatter, `$1\n\n${title}$2`);
} else {
text = title + text;
}
}
// embed attachments directly
let attachments = /!\[(.*)]\((.+)\)|!\[\[(.+)]]/g;

View file

@ -7,7 +7,7 @@
"path": "Cool Test Note.md"
}
],
"stripFrontmatter": true,
"stripFrontmatter": false,
"includeNoteName": true,
"unshareDeletedFiles": false,
"autoUpdateShares": false

View file

@ -1,7 +1,3 @@
---
test: yes
---
This is a cool test note%%with an inline comment%%, my friends!
Chemistry!