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

Apply markdown engine to result provider #232

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

Merged
jdneo merged 8 commits into LeetCode-OpenSource:master from Vigilans:webview-md-result
Mar 27, 2019
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
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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();

AltStyle によって変換されたページ (->オリジナル) /