@@ -23,7 +23,7 @@ export default function Markdown({ text, className }: MarkdownProps) {
2323 // Code blocks
2424 if ( line . startsWith ( '```' ) ) {
2525 if ( inCodeBlock ) {
26- elements . push ( < pre key = { `code-${ i } ` } > { codeBlock . join ( '\n' ) } </ pre > )
26+ elements . push ( < pre key = { `code-${ i . toString ( ) } ` } > { codeBlock . join ( '\n' ) } </ pre > )
2727 inCodeBlock = false
2828 codeBlock = [ ]
2929 } else {
@@ -62,13 +62,13 @@ export default function Markdown({ text, className }: MarkdownProps) {
6262 if ( line . startsWith ( '#' ) ) {
6363 const level = line . split ( ' ' ) [ 0 ] . length
6464 const text = line . slice ( level + 1 )
65- const HeaderTag = `h${ level } ` as keyof JSX . IntrinsicElements
65+ const HeaderTag = `h${ level . toString ( ) } ` as keyof JSX . IntrinsicElements
6666 elements . push ( < HeaderTag key = { i } > { text } </ HeaderTag > )
6767 continue
6868 }
6969
7070 // Images
71- const imageMatch = line . match ( / ! \[ ( .* ?) \] \( ( .* ?) \) / )
71+ const imageMatch = / ! \[ ( .* ?) \] \( ( .* ?) \) / . exec ( line )
7272 if ( imageMatch ) {
7373 const [ , alt , src ] = imageMatch
7474 elements . push ( < img key = { i } src = { src } alt = { alt } /> )
@@ -77,7 +77,7 @@ export default function Markdown({ text, className }: MarkdownProps) {
7777
7878 // Links
7979 if ( line . includes ( '[' ) && line . includes ( ']' ) && line . includes ( '(' ) && line . includes ( ')' ) ) {
80- const linkedLine = line . replace ( / \[ ( .* ?) \] \( ( .* ?) \) / g, ( _ , linkText , url ) => {
80+ const linkedLine = line . replace ( / \[ ( .* ?) \] \( ( .* ?) \) / g, ( _ , linkText : string , url : string ) => {
8181 return `<a href="${ url } ">${ linkText } </a>`
8282 } )
8383 elements . push ( < p dangerouslySetInnerHTML = { { __html : linkedLine } } key = { i } > </ p > )
@@ -87,13 +87,13 @@ export default function Markdown({ text, className }: MarkdownProps) {
8787 // Lists
8888 if ( line . startsWith ( '-' ) || line . startsWith ( '*' ) || line . startsWith ( '+' ) ) {
8989 const listItem = line . slice ( 1 ) . trim ( )
90- listItems . push ( < li key = { `list-item-${ i } ` } > { listItem } </ li > )
90+ listItems . push ( < li key = { `list-item-${ i . toString ( ) } ` } > { listItem } </ li > )
9191 inList = true
9292 continue
9393 }
9494
9595 if ( inList && listItems . length > 0 ) {
96- elements . push ( < ul key = { `list-${ i } ` } > { listItems } </ ul > )
96+ elements . push ( < ul key = { `list-${ i . toString ( ) } ` } > { listItems } </ ul > )
9797 listItems = [ ]
9898 inList = false
9999 }
@@ -104,12 +104,12 @@ export default function Markdown({ text, className }: MarkdownProps) {
104104
105105 // Flush any remaining code block
106106 if ( inCodeBlock && codeBlock . length > 0 ) {
107- elements . push ( < pre key = { `code-${ lines . length } ` } > { codeBlock . join ( '\n' ) } </ pre > )
107+ elements . push ( < pre key = { `code-${ lines . length . toString ( ) } ` } > { codeBlock . join ( '\n' ) } </ pre > )
108108 }
109109
110110 // Flush any remaining list items
111111 if ( inList && listItems . length > 0 ) {
112- elements . push ( < ul key = { `list-${ lines . length } ` } > { listItems } </ ul > )
112+ elements . push ( < ul key = { `list-${ lines . length . toString ( ) } ` } > { listItems } </ ul > )
113113 }
114114
115115 return < div className = { className } > { elements } </ div >
0 commit comments