Skip to content

Commit 2a5c827

Browse files
committed
fix: process code spans before bold in stripMarkdownInline
Code spans have higher precedence than emphasis in CommonMark. Process backtick code spans first so that bold markers inside code spans (e.g. `**text**`) are preserved as literal asterisks. Addresses BugBot review.
1 parent 9e5e7a0 commit 2a5c827

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/lib/formatters/markdown.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,14 @@ export function stripMarkdownInline(md: string): string {
227227
let text = stripColorTags(md);
228228
// Links: [text](url) → text
229229
text = text.replace(/\[([^\]]*)\]\([^)]*\)/g, "$1");
230+
// Code spans first (higher precedence than emphasis in CommonMark):
231+
// `text` → text. Content inside backticks is literal, so bold/italic
232+
// markers inside code spans must not be stripped.
233+
text = text.replace(/`([^`]+)`/g, "$1");
230234
// Bold: **text** → text. Only strip asterisk-based emphasis, not
231235
// underscore-based (_text_) because underscores appear in identifiers
232236
// (e.g. payment_service_handler) and would be corrupted.
233237
text = text.replace(/\*{1,2}([^*]+)\*{1,2}/g, "$1");
234-
// Code spans: `text` → text
235-
text = text.replace(/`([^`]+)`/g, "$1");
236238
// Backslash escapes: \| \< \> \\ \_ \* \[ \] \` → literal character.
237239
// escapeMarkdownCell/escapeMarkdownInline add these for the markdown parser;
238240
// the TTY path unescapes via marked.lexer(), but plain mode must do it here.

0 commit comments

Comments
 (0)