- Notifications
You must be signed in to change notification settings - Fork669
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/webview/markdownEngine.ts Outdated
const validateLink: (link: string) => boolean = md.validateLink; | ||
md.validateLink = (link: string): boolean => { | ||
// support file:// protocal link | ||
return validateLink(link) || link.startsWith("file:"); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Vigilans commentedMar 20, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Now the markdown engine is fully decoupled with webviews with the help of constbody:string=this.markdown.render(solution.body,{lang:this.solution.lang,host:"https://discuss.leetcode.com/",}); |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/webview/markdownEngine.ts Outdated
const validateLink: (link: string) => boolean = md.validateLink; | ||
md.validateLink = (link: string): boolean => { | ||
// support file:// protocal link | ||
return validateLink(link) || link.startsWith("file:"); |
There was a problem hiding this comment.
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...
There was a problem hiding this 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!
Uh oh!
There was an error while loading.Please reload this page.
Introduction
MarkdownEngine
class.Details
file://
protocal.