From 2ca5f648c390969dbda89c82735ed0b90ff319eb Mon Sep 17 00:00:00 2001 From: Turtle Date: Mon, 28 Sep 2026 13:44:46 +0800 Subject: [PATCH] test(client): pin first-line-only frontmatter detection --- .../src/client/markdown/frontmatter.ts | 4 ++-- .../tests/markdown-body.client.spec.tsx | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/client/ui-sidebar-documentpreview/src/client/markdown/frontmatter.ts b/packages/client/ui-sidebar-documentpreview/src/client/markdown/frontmatter.ts index 26c186d03f..ccdbbfe9cd 100644 --- a/packages/client/ui-sidebar-documentpreview/src/client/markdown/frontmatter.ts +++ b/packages/client/ui-sidebar-documentpreview/src/client/markdown/frontmatter.ts @@ -6,8 +6,8 @@ export interface FrontmatterSplit { body: string } -// Opening `---` on the first line, then the first closing `---` or `...` line; `??` lets an -// empty block close on the line right after the opening. +// Only an opening `---` on the first line (after an optional BOM) counts; the block ends at the +// first closing `---` or `...` line, and `??` lets an empty block close on the next line. const FRONTMATTER = /^\uFEFF?---[ \t]*\r?\n(?:([\s\S]*?)\r?\n)??(?:---|\.\.\.)[ \t]*(?:\r?\n|$)/u /** diff --git a/packages/client/ui-sidebar-documentpreview/tests/markdown-body.client.spec.tsx b/packages/client/ui-sidebar-documentpreview/tests/markdown-body.client.spec.tsx index 3bea55f798..c344a9a744 100644 --- a/packages/client/ui-sidebar-documentpreview/tests/markdown-body.client.spec.tsx +++ b/packages/client/ui-sidebar-documentpreview/tests/markdown-body.client.spec.tsx @@ -173,6 +173,16 @@ describe('MarkdownBody', () => { expect(view.container.querySelector('hr')).not.toBeNull() }) + it.each([ + ['a leading blank line', '\n---\nname: pdf\n---\nBody.'], + ['leading text', 'Intro.\n\n---\nname: pdf\n---\nBody.'], + ['an indented opening rule', ' ---\nname: pdf\n---\nBody.'], + ])('treats a delimiter pair after %s as Markdown', (_, text) => { + const view = render() + expect(view.container.querySelector('[data-document-frontmatter]')).toBeNull() + expect(view.getByText('Body.')).toBeDefined() + }) + it('renders empty text and leaves non-text deliveries to their selected implementation', () => { const view = render() expect(view.container.querySelector('[data-document-markdown]')?.textContent).toBe('')