Skip to content

Commit 683c1e8

Browse files
authored
Merge pull request #162 from ccagml/main
题解显示 katex 数学公式
2 parents 808ea42 + e0f5ac8 commit 683c1e8

File tree

6 files changed

+33
-3
lines changed

6 files changed

+33
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## version 2.13.1
2+
3+
- 题解显示 katex 数学公式
4+
15
## version 2.12.3
26

37
- hideScore 配置变化时刷新题目列表

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-leetcode-problem-rating",
33
"displayName": "LeetCode",
44
"description": "LeetCode 官方插件增强, 代码开源, 增加 LeetCode 题目难度分, 给个star吧, 球球了",
5-
"version": "2.12.3",
5+
"version": "2.13.1",
66
"author": "ccagml",
77
"publisher": "ccagml",
88
"license": "MIT",

resources/katexcss/github-markdown.min.css

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/katexcss/kates.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/service/MarkdownService.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import * as hljs from "highlight.js";
1111
import * as MarkdownIt from "markdown-it";
12+
import * as MarkDownItKatex from "markdown-it-katex";
1213
import * as os from "os";
1314
import * as path from "path";
1415
import * as vscode from "vscode";
@@ -30,7 +31,10 @@ class MarkdownService implements vscode.Disposable {
3031
}
3132

3233
public get localResourceRoots(): vscode.Uri[] {
33-
return [vscode.Uri.file(path.join(this.config.extRoot, "media"))];
34+
return [
35+
vscode.Uri.file(path.join(this.config.extRoot, "media")),
36+
vscode.Uri.file(path.join(__dirname, "..", "..", "..", "resources", "katexcss")),
37+
];
3438
}
3539

3640
public dispose(): void {
@@ -108,6 +112,7 @@ class MarkdownService implements vscode.Disposable {
108112
},
109113
});
110114

115+
md.use(MarkDownItKatex);
111116
this.addCodeBlockHighlight(md);
112117
this.addImageUrlCompletion(md);
113118
this.addLinkValidator(md);

src/service/SolutionService.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { BaseWebViewService } from "./BaseWebviewService";
1313
import { markdownService } from "./MarkdownService";
1414
import { IWebViewOption } from "../model/Model";
1515

16+
import * as path from "path";
17+
1618
class SolutionService extends BaseWebViewService {
1719
protected readonly viewType: string = "leetcode.solution";
1820
private problemName: string;
@@ -52,16 +54,32 @@ class SolutionService extends BaseWebViewService {
5254
`| ${lang} | ${auth} | ${votes} |`,
5355
].join("\n")
5456
);
57+
58+
// $\textit
59+
this.solution.body = this.solution.body.replace(/\$\textit/g, "$");
60+
5561
const body: string = markdownService.render(this.solution.body, {
5662
lang: this.solution.lang,
5763
host: "https://discuss.leetcode.com/",
5864
});
65+
// "<link rel=\"stylesheet\" type=\"text/css\" href=\"vscode-resource:/home/cc/.vscode-server/bin/30d9c6cd9483b2cc586687151bcbcd635f373630/extensions/markdown-language-features/media/markdown.css\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"vscode-resource:/home/cc/.vscode-server/bin/30d9c6cd9483b2cc586687151bcbcd635f373630/extensions/markdown-language-features/media/highlight.css\">\n<style>\nbody {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe WPC', 'Segoe UI', system-ui, 'Ubuntu', 'Droid Sans', sans-serif;\n font-size: 14px;\n line-height: 1.6;\n}\n</style>"
66+
// <meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src https:; script-src vscode-resource:; style-src vscode-resource:;"/>
67+
5968
return `
6069
<!DOCTYPE html>
6170
<html>
6271
<head>
63-
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src https:; script-src vscode-resource:; style-src vscode-resource:;"/>
72+
<meta http-equiv="Content-Security-Policy" content="default-src self; img-src vscode-resource:; script-src vscode-resource: 'self' 'unsafe-inline'; style-src vscode-resource: 'self' 'unsafe-inline'; "/>
6473
${styles}
74+
<link rel="stylesheet" type="text/css" href= "vscode-resource:${path.join(
75+
__dirname,
76+
"..",
77+
"..",
78+
"..",
79+
"resources",
80+
"katexcss",
81+
"kates.min.css"
82+
)}">
6583
</head>
6684
<body class="vscode-body 'scrollBeyondLastLine' 'wordWrap' 'showEditorSelection'" style="tab-size:4">
6785
${head}

0 commit comments

Comments
 (0)