Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

added solution link#441

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jdneo merged 5 commits intoLeetCode-OpenSource:masterfromiFun:addArticleLink
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes fromall 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 deletionACKNOWLEDGEMENTS.md
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionssrc/webview/leetCodePreviewProvider.ts
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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 DownExpand 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

[8]ページ先頭

©2009-2025 Movatter.jp