@@ -24,6 +24,17 @@ class LeetCodeSolutionProvider implements Disposable {
24
24
highlight : this . codeHighlighter . bind ( this ) ,
25
25
} ) ;
26
26
this . markdownPath = path . join ( process . env . VSCODE_CWD as string , "resources" , "app" , "extensions" , "markdown-language-features" ) ;
27
+
28
+ // Override code_block rule for highlighting in solution language
29
+ // tslint:disable-next-line:typedef
30
+ this . markdown . renderer . rules [ "code_block" ] = ( tokens , idx , options , _ , self ) => {
31
+ const highlight : string = options . highlight ( tokens [ idx ] . content , undefined ) ;
32
+ return [
33
+ `<pre><code ${ self . renderAttrs ( tokens [ idx ] ) } >` ,
34
+ highlight || this . markdown . utils . escapeHtml ( tokens [ idx ] . content ) ,
35
+ "</code></pre>" ,
36
+ ] . join ( "\n" ) ;
37
+ } ;
27
38
}
28
39
29
40
public async show ( solutionString : string ) : Promise < void > {
@@ -68,11 +79,9 @@ class LeetCodeSolutionProvider implements Disposable {
68
79
if ( ! lang ) {
69
80
lang = this . solution . lang ;
70
81
}
71
- // tslint:disable-next-line:typedef
72
- const hljst = hljs ;
73
- if ( hljst . getLanguage ( lang ) ) {
82
+ if ( hljs . getLanguage ( lang ) ) {
74
83
try {
75
- return hljst . highlight ( lang , code ) . value ;
84
+ return hljs . highlight ( lang , code , true ) . value ;
76
85
} catch ( error ) { /* do not highlight */ }
77
86
}
78
87
return "" ; // use external default escaping
0 commit comments