@@ -221,16 +221,6 @@ const isNpmJsUrlThatCanBeRedirected = (url: URL) => {
221221 return true
222222}
223223
224- const replaceHtmlLink = ( html : string ) => {
225- return html . replace ( / h r e f = " ( [ ^ " ] + ) " / g, ( match , href ) => {
226- if ( isNpmJsUrlThatCanBeRedirected ( new URL ( href , 'https://www.npmjs.com' ) ) ) {
227- const newHref = href . replace ( / ^ h t t p s ? : \/ \/ ( w w w \. ) ? n p m j s \. c o m / , '' )
228- return `href="${ newHref } "`
229- }
230- return match
231- } )
232- }
233-
234224/**
235225 * Resolve a relative URL to an absolute URL.
236226 * If repository info is available, resolve to provider's raw file URLs.
@@ -387,7 +377,8 @@ export async function renderReadmeHtml(
387377 toc . push ( { text : plainText , id, depth } )
388378 }
389379
390- return `<h${ semanticLevel } id="${ id } " data-level="${ depth } ">${ text } </h${ semanticLevel } >\n`
380+ /** The link href uses the unique slug WITHOUT the 'user-content-' prefix, because that will later be added for all links. */
381+ return `<h${ semanticLevel } id="${ id } " data-level="${ depth } "><a href="#${ uniqueSlug } ">${ plainText } </a></h${ semanticLevel } >\n`
391382 }
392383
393384 // Syntax highlighting for code blocks (uses shared highlighter)
@@ -443,14 +434,7 @@ ${html}
443434 return `<blockquote>${ body } </blockquote>\n`
444435 }
445436
446- marked . setOptions ( {
447- renderer,
448- walkTokens : token => {
449- if ( token . type === 'html' ) {
450- token . text = replaceHtmlLink ( token . text )
451- }
452- } ,
453- } )
437+ marked . setOptions ( { renderer } )
454438
455439 const rawHtml = marked . parse ( content ) as string
456440
0 commit comments