Skip to content

Commit d499071

Browse files
committed
fix: add regex to find front matter
1 parent 40cde2b commit d499071

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/main.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,14 +323,16 @@ export default class MediaDbPlugin extends Plugin {
323323
fileContent = `---\n${this.settings.useCustomYamlStringifier ? YAMLConverter.toYaml(fileMetadata) : stringifyYaml(fileMetadata)}---\n` + fileContent;
324324
return fileContent;
325325
} else {
326-
const parts = template.split('---');
326+
const frontMatterRegex = /^---*\n([\s\S]*?)\n---\h*/;
327327

328-
if (parts.length < 3) {
328+
const match = template.match(frontMatterRegex);
329+
330+
if (!match || match.length !== 2) {
329331
throw new Error('Cannot find YAML front matter for template.');
330332
}
331333

332-
let frontMatter = parseYaml(parts[1]);
333-
let fileContent: string = parts[2];
334+
let frontMatter = parseYaml(match[1]);
335+
let fileContent: string = template.replace(frontMatterRegex, '');
334336

335337
// Updating a previous file
336338
if (options.attachFile) {

0 commit comments

Comments
 (0)