@@ -16,68 +16,6 @@ interface MarkdownBlockProps {
1616 markdown ?: string
1717}
1818
19- /**
20- * Custom remark plugin that converts plain URLs in text into clickable links
21- *
22- * The original bug: We were converting text nodes into paragraph nodes,
23- * which broke the markdown structure because text nodes should remain as text nodes
24- * within their parent elements (like paragraphs, list items, etc.).
25- * This caused the entire content to disappear because the structure became invalid.
26- */
27- const remarkUrlToLink = ( ) => {
28- return ( tree : any ) => {
29- // Visit all "text" nodes in the markdown AST (Abstract Syntax Tree)
30- visit ( tree , "text" , ( node : any , index , parent ) => {
31- const urlRegex = / h t t p s ? : \/ \/ [ ^ \s < > ) " ] + / g
32- const matches = node . value . match ( urlRegex )
33-
34- if ( ! matches || ! parent ) {
35- return
36- }
37-
38- const parts = node . value . split ( urlRegex )
39- const children : any [ ] = [ ]
40- const cleanedMatches = matches . map ( ( url : string ) => url . replace ( / [ . , ; : ! ? ' " ] + $ / , "" ) )
41-
42- parts . forEach ( ( part : string , i : number ) => {
43- if ( part ) {
44- children . push ( { type : "text" , value : part } )
45- }
46-
47- if ( cleanedMatches [ i ] ) {
48- const originalUrl = matches [ i ]
49- const cleanedUrl = cleanedMatches [ i ]
50- const removedPunctuation = originalUrl . substring ( cleanedUrl . length )
51-
52- // Create a proper link node with all required properties
53- children . push ( {
54- type : "link" ,
55- url : cleanedUrl ,
56- title : null ,
57- children : [ { type : "text" , value : cleanedUrl } ] ,
58- data : {
59- hProperties : {
60- href : cleanedUrl ,
61- } ,
62- } ,
63- } )
64-
65- if ( removedPunctuation ) {
66- children . push ( { type : "text" , value : removedPunctuation } )
67- }
68- }
69- } )
70-
71- // Replace the original text node with our new nodes in the parent's children array.
72- // This preserves the document structure while adding our links.
73- parent . children . splice ( index ! , 1 , ...children )
74-
75- // Return SKIP to prevent visiting the newly created nodes
76- return [ "skip" , index ! + children . length ]
77- } )
78- }
79- }
80-
8119const StyledMarkdown = styled . div `
8220 code:not(pre > code) {
8321 font-family: var(--vscode-editor-font-family, monospace);
@@ -321,7 +259,6 @@ const MarkdownBlock = memo(({ markdown }: MarkdownBlockProps) => {
321259 < ReactMarkdown
322260 remarkPlugins = { [
323261 remarkGfm ,
324- remarkUrlToLink ,
325262 remarkMath ,
326263 ( ) => {
327264 return ( tree : any ) => {
0 commit comments