Skip to content

Commit 04134da

Browse files
fix: process images before links to correctly strip image markdown
1 parent 1642009 commit 04134da

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/utils/stripMarkdownAndHtml.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ export const stripMarkdownAndHtml = (text: string | null | undefined): string =>
3737
// - Headers: # Header, ## Header, etc.
3838
cleaned = cleaned.replace(/^#{1,6}\s+/gm, '');
3939

40+
// - Images: ![alt](url) -> alt (must come before links to avoid conflicts)
41+
cleaned = cleaned.replace(/!\[([^\]]*)\]\([^)]+\)/g, '$1');
42+
4043
// - Links: [text](url) -> text
4144
cleaned = cleaned.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1');
4245

43-
// - Images: ![alt](url) -> alt
44-
cleaned = cleaned.replace(/!\[([^\]]*)\]\([^)]+\)/g, '$1');
45-
4646
// - Code blocks: `code` -> code
4747
cleaned = cleaned.replace(/`([^`]+)`/g, '$1');
4848

0 commit comments

Comments
 (0)