From 1ef2560faac70352fd5551ab4f6e13c162797b7a Mon Sep 17 00:00:00 2001 From: hypercross Date: Tue, 7 Jul 2026 21:47:25 +0800 Subject: [PATCH] fix: normalize line endings in frontmatter parsing Normalize CRLF line endings to LF before parsing frontmatter to ensure regex matching works consistently across different platforms. --- src/components/doc-data.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/doc-data.ts b/src/components/doc-data.ts index 350ca8b..6bc82e5 100644 --- a/src/components/doc-data.ts +++ b/src/components/doc-data.ts @@ -13,7 +13,9 @@ export interface DocEntry { /** Splits frontmatter and markdown body from a raw .md string. */ function parseFrontmatter(raw: string): Record | null { - const match = raw.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/); + // Handle CRLF line endings by normalizing to LF first + const normalized = raw.replace(/\r\n/g, "\n"); + const match = normalized.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/); if (!match) return null; try { return yaml.load(match[1]) as Record; @@ -23,7 +25,8 @@ function parseFrontmatter(raw: string): Record | null { } function getBody(raw: string): string { - const match = raw.match(/^---\n[\s\S]*?\n---\n?([\s\S]*)$/); + const normalized = raw.replace(/\r\n/g, "\n"); + const match = normalized.match(/^---\n[\s\S]*?\n---\n?([\s\S]*)$/); return match ? match[1] : raw; }