mirror of
https://github.com/Ellpeck/ObsidianJustSharePlease.git
synced 2024-11-29 21:38:34 +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);
|
let text = await this.app.vault.cachedRead(file);
|
||||||
|
|
||||||
// strip frontmatter
|
// strip frontmatter
|
||||||
|
let frontmatter = /^(---\s*\n.*?\n---)\s*\n(.*)$/s;
|
||||||
if (this.settings.stripFrontmatter)
|
if (this.settings.stripFrontmatter)
|
||||||
text = text.replace(/^---\s*\n.*?\n---\s*\n(.*)$/s, "$1");
|
text = text.replace(frontmatter, "$2");
|
||||||
|
|
||||||
// strip comments
|
// strip comments
|
||||||
text = text.replace(/%%.*?%%/sg, "");
|
text = text.replace(/%%.*?%%/sg, "");
|
||||||
|
|
||||||
// include note name
|
// include note name (after frontmatter!)
|
||||||
if (this.settings.includeNoteName)
|
if (this.settings.includeNoteName) {
|
||||||
text = `# ${file.basename}\n\n${text}`;
|
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
|
// embed attachments directly
|
||||||
let attachments = /!\[(.*)]\((.+)\)|!\[\[(.+)]]/g;
|
let attachments = /!\[(.*)]\((.+)\)|!\[\[(.+)]]/g;
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
"path": "Cool Test Note.md"
|
"path": "Cool Test Note.md"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"stripFrontmatter": true,
|
"stripFrontmatter": false,
|
||||||
"includeNoteName": true,
|
"includeNoteName": true,
|
||||||
"unshareDeletedFiles": false,
|
"unshareDeletedFiles": false,
|
||||||
"autoUpdateShares": false
|
"autoUpdateShares": false
|
||||||
|
|
|
@ -1,7 +1,3 @@
|
||||||
---
|
|
||||||
test: yes
|
|
||||||
---
|
|
||||||
|
|
||||||
This is a cool test note%%with an inline comment%%, my friends!
|
This is a cool test note%%with an inline comment%%, my friends!
|
||||||
|
|
||||||
Chemistry!
|
Chemistry!
|
||||||
|
|
Loading…
Reference in a new issue