22// Licensed under the MIT license.
33
44import { commands , ViewColumn } from "vscode" ;
5- import { IProblem } from "../shared" ;
5+ import { getLeetCodeEndpoint } from "../commands/plugin" ;
6+ import { Endpoint , IProblem } from "../shared" ;
67import { ILeetCodeWebviewOption , LeetCodeWebview } from "./LeetCodeWebview" ;
78import { markdownEngine } from "./markdownEngine" ;
89
@@ -73,9 +74,9 @@ class LeetCodePreviewProvider extends LeetCodeWebview {
7374const { title, url, category, difficulty, likes, dislikes, body} = this . description ;
7475const head :string = markdownEngine . render ( `# [${ title } ](${ url } )` ) ;
7576const 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 } |` ,
7980] . join ( "\n" ) ) ;
8081const tags :string = [
8182`<details>` ,
@@ -97,6 +98,7 @@ class LeetCodePreviewProvider extends LeetCodeWebview {
9798) ,
9899`</details>` ,
99100] . join ( "\n" ) ;
101+ const links :string = markdownEngine . render ( `[Discussion](${ this . getDiscussionLink ( url ) } ) | [Solution](${ this . getSolutionLink ( url ) } )` ) ;
100102return `
101103 <!DOCTYPE html>
102104 <html>
@@ -114,6 +116,8 @@ class LeetCodePreviewProvider extends LeetCodeWebview {
114116${ tags }
115117${ companies }
116118${ body }
119+ <hr />
120+ ${ links }
117121${ ! this . sideMode ?button . element :"" }
118122 <script>
119123 const vscode = acquireVsCodeApi();
@@ -172,6 +176,21 @@ class LeetCodePreviewProvider extends LeetCodeWebview {
172176body :body . join ( "\n" ) . replace ( / < p r e > [ \r \n ] * ( [ ^ ] + ?) [ \r \n ] * < \/ p r e > / g, "<pre><code>$1</code></pre>" ) ,
173177} ;
174178}
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+ }
175194}
176195
177196interface IDescription {