@@ -458,6 +458,17 @@ function renderFrontmatterTable(data: Record<string, unknown>): string {
458458 return `<table><thead><tr><th>Key</th><th>Value</th></tr></thead><tbody>\n${ rows } \n</tbody></table>\n`
459459}
460460
461+ // Extract and preserve allowed attributes from HTML heading tags
462+ function extractHeadingAttrs ( attrsString : string ) : string {
463+ if ( ! attrsString ) return ''
464+ const preserved : string [ ] = [ ]
465+ const alignMatch = / \b a l i g n = ( [ " ' ] ? ) ( [ ^ " ' \s > ] + ) \1/ i. exec ( attrsString )
466+ if ( alignMatch ?. [ 2 ] ) {
467+ preserved . push ( `align="${ alignMatch [ 2 ] } "` )
468+ }
469+ return preserved . length > 0 ? ` ${ preserved . join ( ' ' ) } ` : ''
470+ }
471+
461472export async function renderReadmeHtml (
462473 content : string ,
463474 packageName : string ,
@@ -530,17 +541,6 @@ export async function renderReadmeHtml(
530541 return processHeading ( depth , displayHtml , plainText , slugSource )
531542 }
532543
533- // Extract and preserve allowed attributes from HTML heading tags
534- function extractHeadingAttrs ( attrsString : string ) : string {
535- if ( ! attrsString ) return ''
536- const preserved : string [ ] = [ ]
537- const alignMatch = / \b a l i g n = ( [ " ' ] ? ) ( [ ^ " ' \s > ] + ) \1/ i. exec ( attrsString )
538- if ( alignMatch ?. [ 2 ] ) {
539- preserved . push ( `align="${ alignMatch [ 2 ] } "` )
540- }
541- return preserved . length > 0 ? ` ${ preserved . join ( ' ' ) } ` : ''
542- }
543-
544544 // Intercept HTML headings so they get id, TOC entry, and correct semantic level.
545545 // Also intercept raw HTML <a> tags so playground links are collected in the same pass.
546546 const htmlHeadingRe = / < h ( [ 1 - 6 ] ) ( \s [ ^ > ] * ) ? > ( [ \s \S ] * ?) < \/ h \1> / gi
0 commit comments