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('')