mirror of
https://github.com/Ellpeck/ObsidianJustSharePlease.git
synced 2024-11-26 04:08:35 +01:00
fixed note name being included before frontmatter
This commit is contained in:
parent
6537a84562
commit
b1370b772e
3 changed files with 12 additions and 9 deletions
15
src/main.ts
15
src/main.ts
|
@ -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;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
"path": "Cool Test Note.md"
|
||||
}
|
||||
],
|
||||
"stripFrontmatter": true,
|
||||
"stripFrontmatter": false,
|
||||
"includeNoteName": true,
|
||||
"unshareDeletedFiles": false,
|
||||
"autoUpdateShares": false
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
---
|
||||
test: yes
|
||||
---
|
||||
|
||||
This is a cool test note%%with an inline comment%%, my friends!
|
||||
|
||||
Chemistry!
|
||||
|
|
Loading…
Reference in a new issue