Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Export markdownEngine as global variable
  • Loading branch information
Vigilans committed Mar 25, 2019
commit 7559af59d403ce40a4952cc4df92388f389570fe
12 changes: 5 additions & 7 deletions src/webview/leetCodeResultProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@

import { Disposable, ExtensionContext, ViewColumn, WebviewPanel, window } from "vscode";
import { leetCodeChannel } from "../leetCodeChannel";
import { MarkdownEngine } from "./MarkdownEngine";
import { markdownEngine } from "./markdownEngine";

class LeetCodeResultProvider implements Disposable {

private context: ExtensionContext;
private panel: WebviewPanel | undefined;
private mdEngine: MarkdownEngine;

public initialize(context: ExtensionContext): void {
this.mdEngine = new MarkdownEngine();
this.context = context;
}

Expand All @@ -21,7 +19,7 @@ class LeetCodeResultProvider implements Disposable {
this.panel = window.createWebviewPanel("leetcode.result", "Submission Result", ViewColumn.Two, {
retainContextWhenHidden: true,
enableFindWidget: true,
localResourceRoots: this.mdEngine.localResourceRoots,
localResourceRoots: markdownEngine.localResourceRoots,
});

this.panel.onDidDispose(() => {
Expand Down Expand Up @@ -73,11 +71,11 @@ class LeetCodeResultProvider implements Disposable {
}

private getWebViewContent(result: Result): string {
const styles: string = this.mdEngine.getStylesHTML();
const styles: string = markdownEngine.getStylesHTML();
let body: string;
if (result instanceof AcceptResult) {
const accpet: AcceptResult = result as AcceptResult;
body = this.mdEngine.render([
body = markdownEngine.render([
`## ${result.status}`,
``,
`* ${result.passed}`,
Expand All @@ -86,7 +84,7 @@ class LeetCodeResultProvider implements Disposable {
].join("\n"));
} else {
const failed: FailedResult = result as FailedResult;
body = this.mdEngine.render([
body = markdownEngine.render([
`## ${result.status}`,
`* ${result.passed}`,
``,
Expand Down
14 changes: 6 additions & 8 deletions src/webview/leetCodeSolutionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,23 @@

import { Disposable, ExtensionContext, ViewColumn, WebviewPanel, window } from "vscode";
import { IProblem } from "../shared";
import { MarkdownEngine } from "./MarkdownEngine";
import { markdownEngine } from "./markdownEngine";

class LeetCodeSolutionProvider implements Disposable {

private context: ExtensionContext;
private panel: WebviewPanel | undefined;
private mdEngine: MarkdownEngine;

public initialize(context: ExtensionContext): void {
this.context = context;
this.mdEngine = new MarkdownEngine();
}

public async show(solutionString: string, problem: IProblem): Promise<void> {
if (!this.panel) {
this.panel = window.createWebviewPanel("leetCode.solution", "Top Voted Solution", ViewColumn.Active, {
retainContextWhenHidden: true,
enableFindWidget: true,
localResourceRoots: this.mdEngine.localResourceRoots,
localResourceRoots: markdownEngine.localResourceRoots,
});

this.panel.onDidDispose(() => {
Expand Down Expand Up @@ -55,16 +53,16 @@ class LeetCodeSolutionProvider implements Disposable {
}

private getWebViewContent(solution: Solution): string {
const styles: string = this.mdEngine.getStylesHTML();
const styles: string = markdownEngine.getStylesHTML();
const { title, url, lang, author, votes } = solution;
const head: string = this.mdEngine.render(`# [${title}](${url})`);
const head: string = markdownEngine.render(`# [${title}](${url})`);
const auth: string = `[${author}](https://leetcode.com/${author}/)`;
const info: string = this.mdEngine.render([
const info: string = markdownEngine.render([
`| Language | Author | Votes |`,
`| :------: | :------: | :------: |`,
`| ${lang} | ${auth} | ${votes} |`,
].join("\n"));
const body: string = this.mdEngine.render(solution.body, {
const body: string = markdownEngine.render(solution.body, {
lang: solution.lang,
host: "https://discuss.leetcode.com/",
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as path from "path";
import * as vscode from "vscode";
import { leetCodeChannel } from "../leetCodeChannel";

export class MarkdownEngine {
class MarkdownEngine {

private readonly engine: MarkdownIt;
private readonly extRoot: string; // root path of vscode built-in markdown extension
Expand Down Expand Up @@ -106,3 +106,5 @@ export class MarkdownEngine {
};
}
}

export const markdownEngine: MarkdownEngine = new MarkdownEngine();