Skip to content

Commit

Permalink
bugfix: including notes should remove frontmatter and footer
Browse files Browse the repository at this point in the history
  • Loading branch information
MSzturc committed May 25, 2022
1 parent c8ffc92 commit 433dbdb
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/obsidianUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class ObsidianUtils {
private fileSystem: FileSystemAdapter;
private settings: AdvancedSlidesSettings;

private yamlRegex = /^---[^-]*---/;
private yamlRegex = /^---.*?---\n(.*?)($|---)/s;

constructor(app: App, settings: AdvancedSlidesSettings) {
this.app = app;
Expand Down Expand Up @@ -140,11 +140,15 @@ export class ObsidianUtils {
}

const absoluteFilePath = this.absolute(tfile?.path);
let fileContent = readFileSync(absoluteFilePath, { encoding: 'utf-8' });
fileContent = fileContent.replace(this.yamlRegex, '');
const fileContent = readFileSync(absoluteFilePath, { encoding: 'utf-8' });

if (header === null) {
return fileContent;
if (this.yamlRegex.test(fileContent)) {
return this.yamlRegex.exec(fileContent)[1];
}
else {
return fileContent;
}
} else {
const lines = fileContent.split('\n');
const cache = this.app.metadataCache.getFileCache(tfile);
Expand Down

0 comments on commit 433dbdb

Please sign in to comment.