Skip to content

Commit 6478ebc

Browse files
committed
Render cold_block with solution language in SolutionProvider
1 parent 9c01549 commit 6478ebc

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/leetCodeSolutionProvider.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ class LeetCodeSolutionProvider implements Disposable {
2424
highlight: this.codeHighlighter.bind(this),
2525
});
2626
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+
};
2738
}
2839

2940
public async show(solutionString: string): Promise<void> {
@@ -68,11 +79,9 @@ class LeetCodeSolutionProvider implements Disposable {
6879
if (!lang) {
6980
lang = this.solution.lang;
7081
}
71-
// tslint:disable-next-line:typedef
72-
const hljst = hljs;
73-
if (hljst.getLanguage(lang)) {
82+
if (hljs.getLanguage(lang)) {
7483
try {
75-
return hljst.highlight(lang, code).value;
84+
return hljs.highlight(lang, code, true).value;
7685
} catch (error) { /* do not highlight */ }
7786
}
7887
return ""; // use external default escaping

0 commit comments

Comments
 (0)