Skip to content

Commit 06823e5

Browse files
committed
fix: enhance HTML stripping in markdown to preserve backtick spans
1 parent 0b17ba9 commit 06823e5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

app/composables/useMarkdown.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ function stripAndEscapeHtml(text: string, packageName?: string): string {
3333
// Then strip markdown image badges
3434
stripped = stripMarkdownImages(stripped)
3535

36-
// Then strip actual HTML tags (keep their text content)
37-
// Only match tags that start with a letter or / (to avoid matching things like "a < b > c")
38-
stripped = stripped.replace(/<\/?[a-z][^>]*>/gi, '')
36+
// Strip actual HTML tags (keep their text content), but leave tags inside backtick spans
37+
// The alternation matches a backtick span first — if that branch wins the match is kept as-is
38+
stripped = stripped.replace(
39+
/(`[^`]*`)|<\/?[a-z][^>]*>/gi,
40+
(match, codeSpan: string | undefined) => codeSpan ?? '',
41+
)
3942

4043
// Strip HTML comments: <!-- ... --> (including unclosed comments from truncation)
4144
stripped = stripped.replace(/<!--[\s\S]*?(-->|$)/g, '')

0 commit comments

Comments
 (0)