|
2 | 2 | // Licensed under the MIT license.
|
3 | 3 |
|
4 | 4 | import { commands, ViewColumn } from "vscode";
|
5 |
| -import { IProblem } from "../shared"; |
| 5 | +import { getLeetCodeEndpoint } from "../commands/plugin"; |
| 6 | +import { Endpoint, IProblem } from "../shared"; |
6 | 7 | import { ILeetCodeWebviewOption, LeetCodeWebview } from "./LeetCodeWebview";
|
7 | 8 | import { markdownEngine } from "./markdownEngine";
|
8 | 9 |
|
@@ -73,9 +74,9 @@ class LeetCodePreviewProvider extends LeetCodeWebview {
|
73 | 74 | const { title, url, category, difficulty, likes, dislikes, body } = this.description;
|
74 | 75 | const head: string = markdownEngine.render(`# [${title}](${url})`);
|
75 | 76 | const info: string = markdownEngine.render([
|
76 |
| -`| Category | Difficulty | Likes | Dislikes | [Discuss](${url.replace("/description/", "/discuss/?currentPage=1&orderBy=most_votes&query=")}) |`, |
77 |
| -`| :------: | :--------: | :---: | :------: | :-----: |`, |
78 |
| -`| ${category} | ${difficulty} | ${likes} | ${dislikes} | -- |`, |
| 77 | +`| Category | Difficulty | Likes | Dislikes |`, |
| 78 | +`| :------: | :--------: | :---: | :------: |`, |
| 79 | +`| ${category} | ${difficulty} | ${likes} | ${dislikes} |`, |
79 | 80 | ].join("\n"));
|
80 | 81 | const tags: string = [
|
81 | 82 | `<details>`,
|
@@ -97,6 +98,7 @@ class LeetCodePreviewProvider extends LeetCodeWebview {
|
97 | 98 | ),
|
98 | 99 | `</details>`,
|
99 | 100 | ].join("\n");
|
| 101 | +const links: string = markdownEngine.render(`[Discussion](${this.getDiscussionLink(url)}) | [Solution](${this.getSolutionLink(url)})`); |
100 | 102 | return `
|
101 | 103 | <!DOCTYPE html>
|
102 | 104 | <html>
|
@@ -114,6 +116,8 @@ class LeetCodePreviewProvider extends LeetCodeWebview {
|
114 | 116 | ${tags}
|
115 | 117 | ${companies}
|
116 | 118 | ${body}
|
| 119 | +<hr /> |
| 120 | +${links} |
117 | 121 | ${!this.sideMode ? button.element : ""}
|
118 | 122 | <script>
|
119 | 123 | const vscode = acquireVsCodeApi();
|
@@ -172,6 +176,21 @@ class LeetCodePreviewProvider extends LeetCodeWebview {
|
172 | 176 | body: body.join("\n").replace(/<pre>[\r\n]*([^]+?)[\r\n]*<\/pre>/g, "<pre><code>$1</code></pre>"),
|
173 | 177 | };
|
174 | 178 | }
|
| 179 | + |
| 180 | +private getDiscussionLink(url: string): string { |
| 181 | +const endPoint: string = getLeetCodeEndpoint(); |
| 182 | +if (endPoint === Endpoint.LeetCodeCN) { |
| 183 | +return url.replace("/description/", "/comments/"); |
| 184 | +} else if (endPoint === Endpoint.LeetCode) { |
| 185 | +return url.replace("/description/", "/discuss/?currentPage=1&orderBy=most_votes&query="); |
| 186 | +} |
| 187 | + |
| 188 | +return "https://leetcode.com"; |
| 189 | +} |
| 190 | + |
| 191 | +private getSolutionLink(url: string): string { |
| 192 | +return url.replace("/description/", "/solution/"); |
| 193 | +} |
175 | 194 | }
|
176 | 195 |
|
177 | 196 | interface IDescription {
|
|
0 commit comments