Add some rel attributes to links inside markdown (#461)

I currently don't differentiate between "trusted" markdown and
untrusted, but this should be good enough. Basically tells the
browser not to send a referrer, and (not sure if relevant here)
not to expose a window opener object. Also tells search engines
that the link is not endorsed with "nofollow".
This commit is contained in:
Nicolas F 2018-03-26 01:30:07 +02:00 committed by Arylide
parent dd4510f371
commit e9b1f6a6c4
1 changed files with 7 additions and 0 deletions

View File

@ -212,6 +212,13 @@ markdown.renderer.rules.table_open = function (tokens, idx) {
// Format tables nicer (bootstrap). Force auto-width (default is 100%)
return '<table class="table table-striped table-bordered" style="width: auto;">';
}
var defaultRender = markdown.renderer.rules.link_open || function(tokens, idx, options, env, self) {
return self.renderToken(tokens, idx, options);
};
markdown.renderer.rules.link_open = function (tokens, idx, options, env, self) {
tokens[idx].attrPush(['rel', 'noopener nofollow noreferrer']);
return defaultRender(tokens, idx, options, env, self);
}
// Initialise markdown editors on page
document.addEventListener("DOMContentLoaded", function() {