File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -17,11 +17,17 @@ import path from "path";
1717
1818// Extract clean text content from MDX
1919function extractTextFromMDX ( content : string ) : string {
20- return content
20+ let text = content
2121 . replace ( / ^ - - - [ \s \S ] * ?- - - / m, "" ) // Remove frontmatter
2222 . replace ( / ` ` ` [ \s \S ] * ?` ` ` / g, "" ) // Remove code blocks
23- . replace ( / ` ( [ ^ ` ] + ) ` / g, "$1" ) // Remove inline code
24- . replace ( / < [ ^ > ] + > / g, "" ) // Remove HTML/MDX tags
23+ . replace ( / ` ( [ ^ ` ] + ) ` / g, "$1" ) ; // Remove inline code
24+ // Remove HTML/MDX tags recursively to prevent incomplete multi-character sanitization
25+ let prevText ;
26+ do {
27+ prevText = text ;
28+ text = text . replace ( / < [ ^ > ] + > / g, "" ) ;
29+ } while ( text !== prevText ) ;
30+ return text
2531 . replace ( / \* \* ( [ ^ * ] + ) \* \* / g, "$1" ) // Remove bold
2632 . replace ( / \* ( [ ^ * ] + ) \* / g, "$1" ) // Remove italic
2733 . replace ( / # { 1 , 6 } \s + / g, "" ) // Remove headers
You can’t perform that action at this time.
0 commit comments