test(client): pin first-line-only frontmatter detection
This commit is contained in:
1 parent
39c614a143
commit
2ca5f648c3
2 files changed
+12
-2
No files matched your search
@@ -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
|
||||
|
||||
/**
|
||||
|
||||
@@ -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(<MarkdownBody {...props(content([text], true))} />)
|
||||
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(<MarkdownBody {...props({ kind: 'text', text: '', pages: [], eof: true })} />)
|
||||
expect(view.container.querySelector('[data-document-markdown]')?.textContent).toBe('')
|
||||
|
||||
Reference in new issue
Block a user