@@ -53,9 +53,16 @@ export class Renderer extends Marked.Renderer {
53
53
}
54
54
55
55
code ( code : string , language ?: string ) : string {
56
- // a language of `ts, ignore` should really be `ts`
57
- // and it should be lowercase to ensure it has parity with regular github markdown
58
- language = language ?. split ( "," ) ?. [ 0 ] . toLocaleLowerCase ( ) ;
56
+ const isTitleIncluded = language ?. match ( / \s t i t l e = " ( .+ ) " / ) ;
57
+ let title = null ;
58
+ if ( isTitleIncluded ) {
59
+ language = language ! . split ( " " ) [ 0 ] ;
60
+ title = isTitleIncluded [ 1 ] ;
61
+ } else {
62
+ // a language of `ts, ignore` should really be `ts`
63
+ // and it should be lowercase to ensure it has parity with regular github markdown
64
+ language = language ?. split ( "," ) ?. [ 0 ] . toLocaleLowerCase ( ) ;
65
+ }
59
66
60
67
// transform math code blocks into HTML+MathML
61
68
// https://github.blog/changelog/2022-06-28-fenced-block-syntax-for-mathematical-expressions/
@@ -70,7 +77,10 @@ export class Renderer extends Marked.Renderer {
70
77
return `<pre><code class="notranslate">${ he . encode ( code ) } </code></pre>` ;
71
78
}
72
79
const html = Prism . highlight ( code , grammar , language ! ) ;
73
- return `<div class="highlight highlight-source-${ language } notranslate"><pre>${ html } </pre></div>` ;
80
+ const titleHtml = title
81
+ ? `<div class="markdown-code-title">${ title } </div>`
82
+ : `` ;
83
+ return `<div class="highlight highlight-source-${ language } notranslate">${ titleHtml } <pre>${ html } </pre></div>` ;
74
84
}
75
85
76
86
link ( href : string , title : string | null , text : string ) : string {
0 commit comments