Skip to content

Commit 035125e

Browse files
committed
fix(md): allow whitespace after markdown "---"
1 parent 330f6fb commit 035125e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/markdown/src/markdown.lib.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ describe("Markdown", () => {
3434
assertType<{ title: string; count: number } | undefined>(data);
3535
assert.deepEqual(data, { title: "Test", count: 5 });
3636
});
37+
it("extracts and parses header data with trailing spaces after ---", () => {
38+
const text = "--- \ntitle: Test\ncount: 5\n--- \nContent";
39+
const schema = z.object({ title: z.string(), count: z.number() });
40+
const data = md.getHeaderData<{ title: string; count: number }>(text, {
41+
schema,
42+
});
43+
assertType<{ title: string; count: number } | undefined>(data);
44+
assert.deepEqual(data, { title: "Test", count: 5 });
45+
});
3746
it("returns undefined if header data is not present", () => {
3847
const text = "Content";
3948
const data = md.getHeaderData(text);

packages/markdown/src/markdown.lib.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const fromHtml = (html: Stringable) => {
8686
.trim();
8787
};
8888

89-
const HEADER_REGEX = /^---\n([\s\S]*?)\n---\n?/;
89+
const HEADER_REGEX = /^--- *\n([\s\S]*?)\n--- *\n?/;
9090

9191
/**
9292
* Get the header data from a markdown document

0 commit comments

Comments
 (0)