-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
rename sanitize and add hook for URL sanitization #65
Comments
Yeah, this is a good point. Removing
Also a possibility. |
An url filter option would be great 👍 Now that the InlineLexer is exposed in the module i'm doing this to resolve urls, not pretty but at least a workaround until this functionality lands in some form. # monkeypatch to add url resolving to marked
marked.InlineLexer.prototype._outputLink = marked.InlineLexer.prototype.outputLink
marked.InlineLexer.prototype._resolveLink = (href) -> href
marked.InlineLexer.prototype.outputLink = (cap, link) ->
link.href = @_resolveLink link.href
return @_outputLink cap, link
parseMarkdownSync = (content, baseUrl) ->
### Parse markdown *content* and resolve links using *baseUrl*, returns html. ###
marked.InlineLexer.prototype._resolveLink = (href) ->
url.resolve baseUrl, href
tokens = marked.lexer content
...
return marked.parser tokens
Note that autolinks and gfm-links wont be affected since they are not passed through the outputLink method. |
I also have need for some sort of uniform hook / processing for links. I'm looking to use markdown/marked in a commenting system, so there are some tight requirements for the linking features. In particular I'm looking to add rel="nofollow", increment a count whenever a link appears (so I can flag posts as hasLink for moderation) and disable img processing. I've had good luck overriding the Could outputLink, or some other method, perhaps become a clearing house for all urls, and could it potentially be self-contained (no references to "this", for instance)? |
you can use the new-ish Renderer feature (#129) to kill var renderer;
renderer = new marked.Renderer();
renderer.link = function(href, title, text) {
if (/^javascript:/.test(href)) {
return text;
} else {
return marked.Renderer.prototype.link.call(this, href, title, text);
}
}; |
It appears that since this discussion |
The best way to sanitize links is to whitelist desired schemes, usually just |
Sanitize doesn't do all that's required for sanitized HTML. One thing that's important when accepting user input is to sanitize URLs.
The following JavaScript:
Will output the following HTML:
I think the sanitize option would be better named
escapeMarkup
.To solve the URL problem, I think a good path would be to have an URL filter function in the options, with a conservative URL filter as the default.
The text was updated successfully, but these errors were encountered: