Skip to content

Commit eaba061

Browse files
committed
Enrich content in webview
1 parent 16bf8d6 commit eaba061

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/commands/show.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export async function showSolution(node?: LeetCodeNode): Promise<void> {
5252
let solution: string = await leetCodeExecutor.showSolution(node, language);
5353
// remove slash in espaced \'...\'(generated by leetcode's database)
5454
solution = solution.replace(/\\'/g, "'");
55-
await leetCodeSolutionProvider.show(solution);
55+
await leetCodeSolutionProvider.show(solution, node);
5656
} catch (error) {
5757
await promptForOpenOutputChannel("Failed to fetch the top voted solution. Please open the output channel for details.", DialogType.error);
5858
}

src/leetCodeSolutionProvider.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as MarkdownIt from "markdown-it";
66
import * as path from "path";
77
import * as vscode from "vscode";
88
import { Disposable, ExtensionContext, ViewColumn, WebviewPanel, window } from "vscode";
9-
import { Solution } from "./shared";
9+
import { IProblem, Solution } from "./shared";
1010

1111
class LeetCodeSolutionProvider implements Disposable {
1212

@@ -37,7 +37,7 @@ class LeetCodeSolutionProvider implements Disposable {
3737
};
3838
}
3939

40-
public async show(solutionString: string): Promise<void> {
40+
public async show(solutionString: string, problem: IProblem): Promise<void> {
4141
if (!this.panel) {
4242
this.panel = window.createWebviewPanel("leetCode", "Top voted solution", ViewColumn.Active, {
4343
retainContextWhenHidden: true,
@@ -51,7 +51,7 @@ class LeetCodeSolutionProvider implements Disposable {
5151
}
5252

5353
this.solution = this.parseSolution(solutionString);
54-
this.panel.title = this.solution.title;
54+
this.panel.title = problem.name;
5555
this.panel.webview.html = this.getWebViewContent(this.solution);
5656
this.panel.reveal(ViewColumn.Active);
5757
}
@@ -96,6 +96,14 @@ class LeetCodeSolutionProvider implements Disposable {
9696
const styles: string = this.getMarkdownStyles()
9797
.map((style: vscode.Uri) => `<link rel="stylesheet" type="text/css" href="${style.toString()}">`)
9898
.join("\n");
99+
const { title, url, lang, author, votes } = solution;
100+
const head: string = this.markdown.render(`# [${title}](${url})`);
101+
const auth: string = `[${author}](https://leetcode.com/${author}/)`;
102+
const info: string = this.markdown.render([
103+
`| Language | Author | Votes |`,
104+
`| :------: | :------: | :------: |`,
105+
`| ${lang} | ${auth} | ${votes} |`,
106+
].join("\n"));
99107
const body: string = this.markdown.render(solution.body);
100108
return `
101109
<!DOCTYPE html>
@@ -104,6 +112,8 @@ class LeetCodeSolutionProvider implements Disposable {
104112
${styles}
105113
</head>
106114
<body class="vscode-body 'scrollBeyondLastLine' 'wordWrap' 'showEditorSelection'" style="tab-size:4">
115+
${head}
116+
${info}
107117
${body}
108118
</body>
109119
</html>

0 commit comments

Comments
 (0)