File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -210,6 +210,16 @@ const isNpmJsUrlThatCanBeRedirected = (url: URL) => {
210210 return true
211211}
212212
213+ const replaceHtmlLink = ( html : string ) => {
214+ return html . replace ( / h r e f = " ( [ ^ " ] + ) " / g, ( match , href ) => {
215+ if ( isNpmJsUrlThatCanBeRedirected ( new URL ( href , 'https://www.npmjs.com' ) ) ) {
216+ const newHref = href . replace ( / ^ h t t p s ? : \/ \/ ( w w w \. ) ? n p m j s \. c o m / , '' )
217+ return `href="${ newHref } "`
218+ }
219+ return match
220+ } )
221+ }
222+
213223/**
214224 * Resolve a relative URL to an absolute URL.
215225 * If repository info is available, resolve to provider's raw file URLs.
@@ -436,7 +446,14 @@ ${html}
436446 return `<blockquote>${ body } </blockquote>\n`
437447 }
438448
439- marked . setOptions ( { renderer } )
449+ marked . setOptions ( {
450+ renderer,
451+ walkTokens : token => {
452+ if ( token . type === 'html' ) {
453+ token . text = replaceHtmlLink ( token . text )
454+ }
455+ } ,
456+ } )
440457
441458 const rawHtml = marked . parse ( content ) as string
442459
You can’t perform that action at this time.
0 commit comments