Skip to content

Commit 7da9e85

Browse files
committed
-
1 parent 04ba40c commit 7da9e85

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/build/mdn-comments.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ const basePath = new URL(
99
const baseDir = fileURLToPath(basePath);
1010

1111
function extractSummary(markdown: string): string {
12+
// Remove frontmatter (--- at the beginning)
1213
markdown = markdown.replace(/^---[\s\S]+?---\n/, "");
14+
// Normalize line breaks by collapsing consecutive newlines into a single space
1315
const normalizedText = markdown
1416
.split("\n")
1517
.map((line) => line.trim())
@@ -24,15 +26,15 @@ function extractSummary(markdown: string): string {
2426
.replace(
2527
/\{\{\s*(Glossary|HTMLElement|SVGAttr|SVGElement|cssxref|jsxref|HTTPHeader)\s*\(\s*["']((?:\\.|[^"\\])*?)["'].*?\)\s*\}\}/gi,
2628
"$2",
27-
)
29+
) // Extract first argument from multiple templates, handling escaped quotes & spaces
2830
.replace(
2931
/\{\{\s*domxref\s*\(\s*["']((?:\\.|[^"\\])*?)["'][^}]*\)\s*\}\}/gi,
3032
"$1",
31-
)
33+
) // Extract first argument from domxref, handling spaces
3234
.replace(
3335
/\{\{\s*(?:event|jsxref|cssref|specname)\s*\|\s*([^}]+)\s*\}\}/gi,
3436
"$1",
35-
)
37+
) // Handle event, jsxref, cssref, etc.
3638
.replace(/\{\{\s*([^}]+)\s*\}\}/g, (_, match) => `[MISSING: ${match}]`)
3739
.replace(/\[(.*?)\]\(.*?\)/g, "$1")
3840
.replace(/\s+/g, " ")

0 commit comments

Comments
 (0)