Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added solution link #441

Merged
merged 5 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ACKNOWLEDGEMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

A big thanks to the following individuals for contributing:

- [@JIEJIAN21](https://github.com/JIEJIAN21) - thanks for logo and icon design
- [@TsFreddie](https://github.com/TsFreddie) — [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=TsFreddie)
- [@ntt2k](https://github.com/ntt2k) — [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=ntt2k)
- [@purocean](https://github.com/purocean) — [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=purocean)
Expand All @@ -17,4 +18,5 @@ A big thanks to the following individuals for contributing:
- [@houtianze](https://github.com/houtianze) — [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=houtianze)
- [@magic-akari](https://github.com/magic-akari) - [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=magic-akari)
- [@SF-Zhou](https://github.com/SF-Zhou) - [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=SF-Zhou)
- [@JIEJIAN21](https://github.com/JIEJIAN21) - thanks for logo and icon design
- [@fuafa](https://github.com/fuafa) - [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=fuafa)
- [@iFun](https://github.com/iFun) - [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=iFun)
27 changes: 23 additions & 4 deletions src/webview/leetCodePreviewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// Licensed under the MIT license.

import { commands, ViewColumn } from "vscode";
import { IProblem } from "../shared";
import { getLeetCodeEndpoint } from "../commands/plugin";
import { Endpoint, IProblem } from "../shared";
import { ILeetCodeWebviewOption, LeetCodeWebview } from "./LeetCodeWebview";
import { markdownEngine } from "./markdownEngine";

Expand Down Expand Up @@ -73,9 +74,9 @@ class LeetCodePreviewProvider extends LeetCodeWebview {
const { title, url, category, difficulty, likes, dislikes, body } = this.description;
const head: string = markdownEngine.render(`# [${title}](${url})`);
const info: string = markdownEngine.render([
`| Category | Difficulty | Likes | Dislikes | [Discuss](${url.replace("/description/", "/discuss/?currentPage=1&orderBy=most_votes&query=")}) |`,
`| :------: | :--------: | :---: | :------: | :-----: |`,
`| ${category} | ${difficulty} | ${likes} | ${dislikes} | -- |`,
`| Category | Difficulty | Likes | Dislikes |`,
`| :------: | :--------: | :---: | :------: |`,
`| ${category} | ${difficulty} | ${likes} | ${dislikes} |`,
].join("\n"));
const tags: string = [
`<details>`,
Expand All @@ -97,6 +98,7 @@ class LeetCodePreviewProvider extends LeetCodeWebview {
),
`</details>`,
].join("\n");
const links: string = markdownEngine.render(`[Discussion](${this.getDiscussionLink(url)}) | [Solution](${this.getSolutionLink(url)})`);
return `
<!DOCTYPE html>
<html>
Expand All @@ -114,6 +116,8 @@ class LeetCodePreviewProvider extends LeetCodeWebview {
${tags}
${companies}
${body}
<hr />
${links}
${!this.sideMode ? button.element : ""}
<script>
const vscode = acquireVsCodeApi();
Expand Down Expand Up @@ -172,6 +176,21 @@ class LeetCodePreviewProvider extends LeetCodeWebview {
body: body.join("\n").replace(/<pre>[\r\n]*([^]+?)[\r\n]*<\/pre>/g, "<pre><code>$1</code></pre>"),
};
}

private getDiscussionLink(url: string): string {
const endPoint: string = getLeetCodeEndpoint();
if (endPoint === Endpoint.LeetCodeCN) {
return url.replace("/description/", "/comments/");
} else if (endPoint === Endpoint.LeetCode) {
return url.replace("/description/", "/discuss/?currentPage=1&orderBy=most_votes&query=");
}

return "https://leetcode.com";
}

private getSolutionLink(url: string): string {
return url.replace("/description/", "/solution/");
}
}

interface IDescription {
Expand Down