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

Bring markdown engine into submission provider#398

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 1 commit intomasterfromvigilans/submission-md
Sep 22, 2019
Merged
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
68 changes: 59 additions & 9 deletionssrc/webview/leetCodeSubmissionProvider.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,10 +9,10 @@ import { markdownEngine } from "./markdownEngine";
class LeetCodeSubmissionProvider extends LeetCodeWebview {

protected readonly viewType: string = "leetcode.submission";
private result:string;
private result:IResult;

public show(result: string): void {
this.result =result;
public show(resultString: string): void {
this.result =this.parseResult(resultString);
this.showWebviewInternal();
this.showKeybindingsHint();
}
Expand All@@ -25,18 +25,36 @@ class LeetCodeSubmissionProvider extends LeetCodeWebview {
}

protected getWebviewContent(): string {
return `<!DOCTYPE html>
<html lang="en">
const styles: string = markdownEngine.getStyles();
const title: string = `## ${this.result.messages[0]}`;
const messages: string[] = this.result.messages.slice(1).map((m: string) => `* ${m}`);
const sections: string[] = Object.keys(this.result)
.filter((key: string) => key !== "messages")
.map((key: string) => [
`### ${key}`,
"```",
this.result[key].join("\n"),
"```",
].join("\n"));
const body: string = markdownEngine.render([
title,
...messages,
...sections,
].join("\n"));
return `
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src https:; script-src vscode-resource:; style-src vscode-resource:;"/>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
${markdownEngine.getStyles()}
${styles}
</head>
<body>
<pre><code>${this.result.trim()}</code></pre>
<body class="vscode-body 'scrollBeyondLastLine' 'wordWrap' 'showEditorSelection'" style="tab-size:4">
${body}
</body>
</html>`;
</html>
`;
}

protected onDidDisposeWebview(): void {
Expand All@@ -52,6 +70,38 @@ class LeetCodeSubmissionProvider extends LeetCodeWebview {
(): Promise<any> => openKeybindingsEditor("leetcode solution"),
);
}

private parseResult(raw: string): IResult {
raw = raw.concat(" √ "); // Append a dummy sentinel to the end of raw string
const regSplit: RegExp = / [√×✔✘vx] ([^]+?)\n(?= [√×✔✘vx] )/g;
const regKeyVal: RegExp = /(.+?): ([^]*)/;
const result: IResult = { messages: [] };
let entry: RegExpExecArray | null;
do {
entry = regSplit.exec(raw);
if (!entry) {
continue;
}
const kvMatch: RegExpExecArray | null = regKeyVal.exec(entry[1]);
if (kvMatch) {
const [key, value] = kvMatch.slice(1);
if (value) { // Do not show empty string
if (!result[key]) {
result[key] = [];
}
result[key].push(value);
}
} else {
result.messages.push(entry[1]);
}
} while (entry);
return result;
}
}

interface IResult {
[key: string]: string[];
messages: string[];
}

export const leetCodeSubmissionProvider: LeetCodeSubmissionProvider = new LeetCodeSubmissionProvider();

[8]ページ先頭

©2009-2025 Movatter.jp