diff --git a/app/views/common/markdown.scala.html b/app/views/common/markdown.scala.html index d174c5bb2..9688e31bd 100644 --- a/app/views/common/markdown.scala.html +++ b/app/views/common/markdown.scala.html @@ -34,6 +34,7 @@ htOptions.sIssuesUrl = "@routes.IssueApp.issues(project.owner, project.name)"; htOptions.sProjectUrl = "@routes.ProjectApp.project(project.owner, project.name)"; htOptions.sApplicationContext = "@play.Configuration.root().getString("application.context")"; + htOptions.bNoReferrer = "@play.Configuration.root().getString("application.noreferrer")" } // Reusable markdown renderer diff --git a/public/javascripts/common/yobi.Markdown.js b/public/javascripts/common/yobi.Markdown.js index ed1d77709..4fe026a40 100644 --- a/public/javascripts/common/yobi.Markdown.js +++ b/public/javascripts/common/yobi.Markdown.js @@ -31,6 +31,7 @@ yobi.Markdown = (function(htOptions){ _initVar(htOptions); _enableMarkdown(htOptions.aTarget); + _initializeMarkdownRenderer(); } /** @@ -42,11 +43,13 @@ yobi.Markdown = (function(htOptions){ htVar.sProjectUrl = htOptions.sProjectUrl; htVar.bBreaks = htOptions.bBreaks; htVar.sApplicationContext = htOptions.sApplicationContext; + htVar.bNoReferrer = htOptions.bNoReferrer; htVar.sUserRules = '[a-zA-Z0-9_\\-\\.\\/]'; htVar.sProjecRules = '[a-zA-Z0-9_\\-\\.]'; htVar.sIssueRules = '\\d'; htVar.sSha1Rules = '[a-f0-9]{7,40}'; htVar.htFilter = new Filter(); + htVar.htMarkedOption = { "gfm" : true, "tables" : true, @@ -68,6 +71,72 @@ yobi.Markdown = (function(htOptions){ }; } + function _initializeMarkdownRenderer() { + var renderer = new marked.Renderer(); + renderer.link = function(href, title, text) { + + var link = $('', { + href : _removeJavascript2Href(href), + title : title, + text: text + }); + + if(htVar.bNoReferrer && !isInternalLink(href)) link.attr('rel', "noreferrer"); + + return $('