diff --git a/packages/parser/src/core.ts b/packages/parser/src/core.ts index e57c6982ed..a76d6a1d3e 100644 --- a/packages/parser/src/core.ts +++ b/packages/parser/src/core.ts @@ -68,12 +68,16 @@ export function parseSlide(raw: string): SlideInfoBase { const result = matter(raw) let note: string | undefined const frontmatter = result.data || {} - const content = result.content - .trim() - .replace(/$/g, (_, v = '') => { - note = v.trim() - return '' - }) + let content = result.content.trim() + + const comments = Array.from(content.matchAll(//g)) + if (comments.length) { + const last = comments[comments.length - 1] + if (last.index && last.index + last[0].length >= content.length) { + note = last[1].trim() + content = content.slice(0, last.index).trim() + } + } const title = frontmatter.title || frontmatter.name || content.match(/^#+ (.*)$/m)?.[1]?.trim() diff --git a/test/__snapshots__/parser.test.ts.snap b/test/__snapshots__/parser.test.ts.snap index dd748cd861..0cd323c976 100644 --- a/test/__snapshots__/parser.test.ts.snap +++ b/test/__snapshots__/parser.test.ts.snap @@ -136,7 +136,7 @@ title: Hi }, }, "index": 1, - "note": "This is notes", + "note": "This is note", "raw": "--- meta: title: FooBar @@ -147,7 +147,7 @@ layout: center # Hello ", "start": 8, @@ -170,22 +170,25 @@ This is notes }, Object { "content": " - + Hey ", - "end": 24, + "end": 26, "frontmatter": Object { "layout": "text", }, "index": 3, - "note": undefined, + "note": "This is note", "raw": "--- layout: text --- - + Hey + ", "start": 19, "title": undefined, @@ -199,7 +202,7 @@ this should be treated as code block ---- \`\`\` ", - "end": 33, + "end": 35, "frontmatter": Object {}, "index": 4, "note": undefined, @@ -212,7 +215,7 @@ this should be treated as code block \`\`\` ", - "start": 25, + "start": 27, "title": undefined, }, ] diff --git a/test/fixtures/markdown/frontmatter.md b/test/fixtures/markdown/frontmatter.md index 4f70ab6839..4b50f7f78f 100644 --- a/test/fixtures/markdown/frontmatter.md +++ b/test/fixtures/markdown/frontmatter.md @@ -13,15 +13,17 @@ meta: layout: center --- # Hello - + --- # Morning --- layout: text --- - + Hey + + --- ```md