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

Refactor solution webview to reuse markdown engine#224

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 7 commits intoLeetCode-OpenSource:masterfromVigilans:markdown-engine
Mar 21, 2019
Merged

Refactor solution webview to reuse markdown engine#224

jdneo merged 7 commits intoLeetCode-OpenSource:masterfromVigilans:markdown-engine
Mar 21, 2019

Conversation

Vigilans
Copy link
Contributor

Introduction

Details

  • Add link validator logic, making it supportfile:// protocal.
  • Enhanced indented code block highlight logic.
  • Correction of multiple unsupported alias of language(e.g. python3)
  • Completion of image url in solution markdown(e.g. /asset/... ->https://discuss.leetcode.com/asset/..., refer tothis solution)

@VigilansVigilans requested a review fromjdneoMarch 19, 2019 14:50
const validateLink: (link: string) => boolean = md.validateLink;
md.validateLink = (link: string): boolean => {
// support file:// protocal link
return validateLink(link) || link.startsWith("file:");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Could you explain more why we need the validator here?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is the routine adopted by built-in markdown exntesion'sMarkdownEngine, I think it may enables us to validate local file link, which may be useful in local debugger.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Ok... Actually still not quite understand... I think it's a worth investigating topic. It's fine to leave it here in this PR...

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Document from markdown-it:

MarkdownIt#validateLink(url)Boolean

Link validation function. CommonMark allows too much in links. By default we disable#"auto">You can change this behaviour:

varmd=require('markdown-it')();// enable everythingmd.validateLink=function(){returntrue;}

Since we will deal with local files in WebView, chances are that it will be helpful to enablefile: link.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I looked into the source code, and found that it was made to prevent XSS attack. Here are some examples:

  • When parsing image and link:
if(res.ok){href=state.md.normalizeLink(res.str);if(state.md.validateLink(href)){pos=res.pos;}else{href='';}}

IfvalidateLink does not pass, thenhref is screened out.

  • The same goes on for reference-link or auto link:
href=state.md.normalizeLink(res.str);if(!state.md.validateLink(href)){returnfalse;}

So, it is indeed necessary to loose the restriction to allowfile:// protocol.

@Vigilans
Copy link
ContributorAuthor

Vigilans commentedMar 20, 2019
edited
Loading

Now the markdown engine is fully decoupled with webviews with the help ofenv parameter:

constbody:string=this.markdown.render(solution.body,{lang:this.solution.lang,host:"https://discuss.leetcode.com/",});

const validateLink: (link: string) => boolean = md.validateLink;
md.validateLink = (link: string): boolean => {
// support file:// protocal link
return validateLink(link) || link.startsWith("file:");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Ok... Actually still not quite understand... I think it's a worth investigating topic. It's fine to leave it here in this PR...

Copy link
Member

@jdneojdneo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Much much better. Just some small change requests.

Thank you!

@jdneojdneo added this to the0.13.2 milestoneMar 20, 2019
@jdneojdneo merged commit0552af2 intoLeetCode-OpenSource:masterMar 21, 2019
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@jdneojdneojdneo approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
0.13.2
Development

Successfully merging this pull request may close these issues.

2 participants
@Vigilans@jdneo

[8]ページ先頭

©2009-2025 Movatter.jp