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

Commitef4bcbd

Browse files
Vigilansjdneo
authored andcommitted
fix: Bring markdown engine into submission provider (LeetCode-OpenSource#398)
1 parent5e51132 commitef4bcbd

File tree

1 file changed

+59
-9
lines changed

1 file changed

+59
-9
lines changed

‎src/webview/leetCodeSubmissionProvider.ts

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import { markdownEngine } from "./markdownEngine";
99
classLeetCodeSubmissionProviderextendsLeetCodeWebview{
1010

1111
protectedreadonlyviewType:string="leetcode.submission";
12-
privateresult:string;
12+
privateresult:IResult;
1313

14-
publicshow(result:string):void{
15-
this.result=result;
14+
publicshow(resultString:string):void{
15+
this.result=this.parseResult(resultString);
1616
this.showWebviewInternal();
1717
this.showKeybindingsHint();
1818
}
@@ -25,18 +25,36 @@ class LeetCodeSubmissionProvider extends LeetCodeWebview {
2525
}
2626

2727
protectedgetWebviewContent():string{
28-
return`<!DOCTYPE html>
29-
<html lang="en">
28+
conststyles:string=markdownEngine.getStyles();
29+
consttitle:string=`##${this.result.messages[0]}`;
30+
constmessages:string[]=this.result.messages.slice(1).map((m:string)=>`*${m}`);
31+
constsections:string[]=Object.keys(this.result)
32+
.filter((key:string)=>key!=="messages")
33+
.map((key:string)=>[
34+
`###${key}`,
35+
"```",
36+
this.result[key].join("\n"),
37+
"```",
38+
].join("\n"));
39+
constbody:string=markdownEngine.render([
40+
title,
41+
...messages,
42+
...sections,
43+
].join("\n"));
44+
return`
45+
<!DOCTYPE html>
46+
<html>
3047
<head>
3148
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src https:; script-src vscode-resource:; style-src vscode-resource:;"/>
3249
<meta charset="UTF-8">
3350
<meta name="viewport" content="width=device-width, initial-scale=1.0">
34-
${markdownEngine.getStyles()}
51+
${styles}
3552
</head>
36-
<body>
37-
<pre><code>${this.result.trim()}</code></pre>
53+
<body>
54+
${body}
3855
</body>
39-
</html>`;
56+
</html>
57+
`;
4058
}
4159

4260
protectedonDidDisposeWebview():void{
@@ -52,6 +70,38 @@ class LeetCodeSubmissionProvider extends LeetCodeWebview {
5270
():Promise<any>=>openKeybindingsEditor("leetcode solution"),
5371
);
5472
}
73+
74+
privateparseResult(raw:string):IResult{
75+
raw=raw.concat(" √ ");// Append a dummy sentinel to the end of raw string
76+
constregSplit:RegExp=/[×vx]([^]+?)\n(?=[×vx])/g;
77+
constregKeyVal:RegExp=/(.+?):([^]*)/;
78+
constresult:IResult={messages:[]};
79+
letentry:RegExpExecArray|null;
80+
do{
81+
entry=regSplit.exec(raw);
82+
if(!entry){
83+
continue;
84+
}
85+
constkvMatch:RegExpExecArray|null=regKeyVal.exec(entry[1]);
86+
if(kvMatch){
87+
const[key,value]=kvMatch.slice(1);
88+
if(value){// Do not show empty string
89+
if(!result[key]){
90+
result[key]=[];
91+
}
92+
result[key].push(value);
93+
}
94+
}else{
95+
result.messages.push(entry[1]);
96+
}
97+
}while(entry);
98+
returnresult;
99+
}
100+
}
101+
102+
interfaceIResult{
103+
[key:string]:string[];
104+
messages:string[];
55105
}
56106

57107
exportconstleetCodeSubmissionProvider:LeetCodeSubmissionProvider=newLeetCodeSubmissionProvider();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp