@@ -39,20 +39,22 @@ export class Renderer extends Marked.Renderer {
3939 this . #slugger = new GitHubSlugger ( ) ;
4040 }
4141
42- override heading (
43- text : string ,
44- level : 1 | 2 | 3 | 4 | 5 | 6 ,
45- raw : string ,
46- ) : string {
42+ override heading ( {
43+ tokens,
44+ depth,
45+ text : raw ,
46+ } : Marked . Tokens . Heading ) : string {
47+ const text = this . parser . parseInline ( tokens ) ;
4748 const slug = this . #slugger. slug ( raw ) ;
48- return `<h${ level } id="${ slug } "><a class="anchor" aria-hidden="true" tabindex="-1" href="#${ slug } "><svg class="octicon octicon-link" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>${ text } </h${ level } >\n` ;
49+ return `<h${ depth } id="${ slug } "><a class="anchor" aria-hidden="true" tabindex="-1" href="#${ slug } "><svg class="octicon octicon-link" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>${ text } </h${ depth } >\n` ;
4950 }
5051
51- override image ( src : string , title : string | null , alt : string ) : string {
52- return `<img src="${ src } " alt="${ alt } " title="${ title ?? "" } " />` ;
52+ override image ( { href , title, text } : Marked . Tokens . Image ) : string {
53+ return `<img src="${ href } " alt="${ text } " title="${ title ?? "" } " />` ;
5354 }
5455
55- override code ( code : string , language ?: string ) : string {
56+ override code ( { text, lang } : Marked . Tokens . Code ) : string {
57+ let language = lang ;
5658 const isTitleIncluded = language ?. match ( / \s t i t l e = " ( .+ ) " / ) ;
5759 let title = null ;
5860 if ( isTitleIncluded ) {
@@ -67,23 +69,24 @@ export class Renderer extends Marked.Renderer {
6769 // transform math code blocks into HTML+MathML
6870 // https://github.blog/changelog/2022-06-28-fenced-block-syntax-for-mathematical-expressions/
6971 if ( language === "math" && this . allowMath ) {
70- return katex . renderToString ( code , { displayMode : true } ) ;
72+ return katex . renderToString ( text , { displayMode : true } ) ;
7173 }
7274 const grammar =
7375 language && Object . hasOwnProperty . call ( Prism . languages , language )
7476 ? Prism . languages [ language ]
7577 : undefined ;
7678 if ( grammar === undefined ) {
77- return `<pre><code class="notranslate">${ he . encode ( code ) } </code></pre>` ;
79+ return `<pre><code class="notranslate">${ he . encode ( text ) } </code></pre>` ;
7880 }
79- const html = Prism . highlight ( code , grammar , language ! ) ;
81+ const html = Prism . highlight ( text , grammar , language ! ) ;
8082 const titleHtml = title
8183 ? `<div class="markdown-code-title">${ title } </div>`
8284 : `` ;
8385 return `<div class="highlight highlight-source-${ language } notranslate">${ titleHtml } <pre>${ html } </pre></div>` ;
8486 }
8587
86- override link ( href : string , title : string | null , text : string ) : string {
88+ override link ( { href, title, tokens } : Marked . Tokens . Link ) : string {
89+ const text = this . parser . parseInline ( tokens ) ;
8790 const titleAttr = title ? ` title="${ title } "` : "" ;
8891 if ( href . startsWith ( "#" ) ) {
8992 return `<a href="${ href } "${ titleAttr } >${ text } </a>` ;
@@ -131,10 +134,8 @@ function mathify(markdown: string) {
131134
132135function getOpts ( opts : RenderOptions ) {
133136 return {
134- baseUrl : opts . baseUrl ,
135137 breaks : opts . breaks ?? false ,
136138 gfm : true ,
137- mangle : false ,
138139 renderer : opts . renderer ? opts . renderer : new Renderer ( opts ) ,
139140 async : false ,
140141 } ;
@@ -383,7 +384,7 @@ function stripTokens(
383384 index += 1 ;
384385 }
385386
386- if ( "tokens" in token && token . tokens ) {
387+ if ( "tokens" in token && token . tokens && token . type !== "image" ) {
387388 stripTokens ( token . tokens , sections , token . type === "heading" ) ;
388389 }
389390
0 commit comments