From ab3374222832dc7f906f7961f55e48878147cf3f Mon Sep 17 00:00:00 2001
From: Sheng Chen
| N/A |
| `leetcode.enableStatusBar` | Specify whether the LeetCode status bar will be shown or not. | `true` |
+| `leetcode.nodePath` | Specify the `Node.js` executable path. | `node` |
## Troubleshooting
When you meet any problem, you can check the [Troubleshooting Page](https://github.com/jdneo/vscode-leetcode/wiki/Troubleshooting) first.
diff --git a/docs/README_zh-CN.md b/docs/README_zh-CN.md
index dda1b4ac..b91d4ad2 100644
--- a/docs/README_zh-CN.md
+++ b/docs/README_zh-CN.md
@@ -29,7 +29,7 @@
## 运行条件
- [VS Code 1.23.0+](https://code.visualstudio.com/)
- [Node.js 8+](https://nodejs.org)
- > 注意:请确保`Node`在`PATH`环境变量中,您可以通过执行:`node -v`进行查看。
+ > 注意:请确保`Node`在`PATH`环境变量中。您也可以通过设定 `leetcode.nodePath` 选项来指定 `Node.js` 可执行文件的路径。
## 快速开始
@@ -138,6 +138,7 @@
| `leetcode.endpoint` | 指定使用的终端,可用终端有:`leetcode`, `leetcode-cn` | `leetcode` |
| `leetcode.outputFolder` | 指定保存文件时所用的相对文件夹路径。除了用户自定义路径外,也可以使用保留项,包括:
| N/A |
| `leetcode.enableStatusBar` | 指定是否在 VS Code 下方显示插件状态栏。 | `true` |
+| `leetcode.nodePath` | 指定 `Node.js` 可执行文件的路径。 | `node` |
## 疑难解答
在遇到任何问题时,可以先查看一下[疑难解答](https://github.com/jdneo/vscode-leetcode/wiki/%E7%96%91%E9%9A%BE%E8%A7%A3%E7%AD%94)文档寻求帮助。
diff --git a/package-lock.json b/package-lock.json
index 784300c5..9c6129fa 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "vscode-leetcode",
- "version": "0.13.1",
+ "version": "0.13.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
diff --git a/package.json b/package.json
index f57b6fef..675fce5d 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "vscode-leetcode",
"displayName": "LeetCode",
"description": "Solve LeetCode problems in VS Code",
- "version": "0.13.1",
+ "version": "0.13.2",
"author": "Sheng Chen",
"publisher": "shengchen",
"license": "MIT",
From d93597736ab7a4b69c0dc7e5b1056cf2e7b86145 Mon Sep 17 00:00:00 2001
From: Ye Zhihao ${result.trim()}
-
- `;
+ `;
}
}
-interface IResult {
- [key: string]: string[];
- messages: string[];
-}
-
export const leetCodeResultProvider: LeetCodeResultProvider = new LeetCodeResultProvider();
From 0bec0c4103c79569f74a4c3e26b4bf6969159bc6 Mon Sep 17 00:00:00 2001
From: Ye Zhihao ${result.trim()}
+
`;
}
From ce2eb30f9b9141682daff663d82130b136a133d1 Mon Sep 17 00:00:00 2001
From: Ye Zhihao ${result.trim()}
diff --git a/src/webview/leetCodeSolutionProvider.ts b/src/webview/leetCodeSolutionProvider.ts
index 6243af02..8a378208 100644
--- a/src/webview/leetCodeSolutionProvider.ts
+++ b/src/webview/leetCodeSolutionProvider.ts
@@ -53,7 +53,7 @@ class LeetCodeSolutionProvider implements Disposable {
}
private getWebViewContent(solution: Solution): string {
- const styles: string = markdownEngine.getStylesHTML();
+ const styles: string = markdownEngine.getStyles();
const { title, url, lang, author, votes } = solution;
const head: string = markdownEngine.render(`# [${title}](${url})`);
const auth: string = `[${author}](https://leetcode.com/${author}/)`;
diff --git a/src/webview/markdownEngine.ts b/src/webview/markdownEngine.ts
index b3a45a4a..8ebada23 100644
--- a/src/webview/markdownEngine.ts
+++ b/src/webview/markdownEngine.ts
@@ -7,39 +7,70 @@ import * as os from "os";
import * as path from "path";
import * as vscode from "vscode";
import { leetCodeChannel } from "../leetCodeChannel";
+import { isWindows } from "../utils/osUtils";
-class MarkdownEngine {
+class MarkdownEngine implements vscode.Disposable {
- private readonly engine: MarkdownIt;
- private readonly extRoot: string; // root path of vscode built-in markdown extension
+ private engine: MarkdownIt;
+ private config: MarkdownConfiguration;
+ private listener: vscode.Disposable;
public constructor() {
- this.engine = this.initEngine();
- this.extRoot = path.join(vscode.env.appRoot, "extensions", "markdown-language-features");
+ this.reload();
+ this.listener = vscode.workspace.onDidChangeConfiguration((event: vscode.ConfigurationChangeEvent) => {
+ if (event.affectsConfiguration("markdown")) {
+ this.reload();
+ }
+ }, this);
}
public get localResourceRoots(): vscode.Uri[] {
- return [vscode.Uri.file(path.join(this.extRoot, "media"))];
+ return [vscode.Uri.file(path.join(this.config.extRoot, "media"))];
}
- public get styles(): vscode.Uri[] {
- try {
- const stylePaths: string[] = require(path.join(this.extRoot, "package.json"))["contributes"]["markdown.previewStyles"];
- return stylePaths.map((p: string) => vscode.Uri.file(path.join(this.extRoot, p)).with({ scheme: "vscode-resource" }));
- } catch (error) {
- leetCodeChannel.appendLine("[Error] Fail to load built-in markdown style file.");
- return [];
- }
+ public dispose(): void {
+ this.listener.dispose();
}
- public getStylesHTML(): string {
- return this.styles.map((style: vscode.Uri) => ``).join(os.EOL);
+ public reload(): void {
+ this.engine = this.initEngine();
+ this.config = new MarkdownConfiguration();
}
public render(md: string, env?: any): string {
return this.engine.render(md, env);
}
+ public getStyles(): string {
+ return [
+ this.getBuiltinStyles(),
+ this.getSettingsStyles(),
+ ].join(os.EOL);
+ }
+
+ private getBuiltinStyles(): string {
+ let styles: vscode.Uri[] = [];
+ try {
+ const stylePaths: string[] = require(path.join(this.config.extRoot, "package.json"))["contributes"]["markdown.previewStyles"];
+ styles = stylePaths.map((p: string) => vscode.Uri.file(path.join(this.config.extRoot, p)).with({ scheme: "vscode-resource" }));
+ } catch (error) {
+ leetCodeChannel.appendLine("[Error] Fail to load built-in markdown style file.");
+ }
+ return styles.map((style: vscode.Uri) => ``).join(os.EOL);
+ }
+
+ private getSettingsStyles(): string {
+ return [
+ ``,
+ ].join(os.EOL);
+ }
+
private initEngine(): MarkdownIt {
const md: MarkdownIt = new MarkdownIt({
linkify: true,
@@ -107,4 +138,29 @@ class MarkdownEngine {
}
}
+// tslint:disable-next-line: max-classes-per-file
+class MarkdownConfiguration {
+
+ public readonly extRoot: string; // root path of vscode built-in markdown extension
+ public readonly lineHeight: number;
+ public readonly fontSize: number;
+ public readonly fontFamily: string;
+
+ public constructor() {
+ const markdownConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("markdown");
+ this.extRoot = path.join(vscode.env.appRoot, "extensions", "markdown-language-features");
+ this.lineHeight = Math.max(0.6, +markdownConfig.get${result.trim()}
tK7bdx98Jcp-N0RA17h3QjP?ta_$C
zt|Mp$j0MZVMA>k@d=&GK6{e|s+iPQ|`}#0`azNbSs!@ado-mCGa}Hp5arPdxg3e*f
zrtxi>A(#oOQQHiA@$J7+2A|ewD}CQd#YcJubfv#!4mK7<+_4`NV8$EqE%9y(;Rk^1
z?(O_-6EZJ$wZ-oakknsI*V!LD-?>UOPBK1z-VnY+e!hL^?W3QoAKquu)3=Dk+-xn;
zKOG#_)XUI@LYm{p&h)D8>|6y 1dfo7Q!hDTVv^C7F<*ZW%#(oXA2Xd4}Ag{XG^q
z_@X|fj^cpv@M54BXb+?!Y9ZBTe)AOG41qUDTt*VWUu)n_$YbeF6sVxvMWh~%XUlA(15EsL=TGab>n_T@4KiELrtyHr?~rO
zayifIq=#La!mJX69N+c&ZiB3nY^MC`<-p1?d1}l`u0CF6nxIyM>CKNg0%E
RBE00c?)VMB!dWAwS$QmmQWY2iiZu<|57k5%WvL
z}|4|%=4$<bzcF-Cz2A(F(dg8
zQ(30-@7hl-PT;eGF%d^nkCyIYYbLPGs4Q2Y_NBh--204@hy{^6St;RzR}`KLprF;y
zzEd`jwnt5P=iiu_ro;tTASb-Hdqj8#3|b$~)}ODx>+sNeCv=x0YS5+1ZNMm5If_U~
zx(euW@|V8MA0#!vQA#h7S=(g;-9#G(iK(UE
z#MoiKK#@cK+vW2fI#zKG(>H?b9+o`?Or$}E*+w@;i?|Wr!1{2JZePL&_ye*|2v`Oc
z)xEAHmP`Ca82sAQfdPF;vQ*W5)aOLuBwK9|$
~6>
zDRJj%fP|NMs<_Bhe*ZRNrKm0Yvkj3?^nZ)w)91)@q{4BJ0X>rgH9rzy3cEg^U%SOr
z2v)Gzn4r~WqCKt;M6
3XJziEfb0_R79rogwdKqK8|nhN+*=lKgn4?tK8i~Tg^z`YDF0znSPStR@z(>H
zq$GD`Lv&r
x{mb%%L0?^78X=Ym0Z(s^1b`58(n
z