ignore username matches inside <pre> or <code>

also remember, lazy ? faster than greedy, less backtracking
This commit is contained in:
Jeff Atwood 2013-04-26 15:11:26 -07:00
parent dd9ea50456
commit 01e0226086

View File

@ -142,9 +142,9 @@ Discourse.Markdown = {
converter.hooks.chain("postConversion", function(text) {
if (!text) return "";
// don't do @username mentions inside <pre> blocks
text = text.replace(/<pre>([\s\S]*@[\s\S]*)<\/pre>/gi, function(wholeMatch, inner) {
return "<pre>" + (inner.replace(/@/g, '&#64;')) + "</pre>";
// don't do @username mentions inside <pre> or <code> blocks
text = text.replace(/<(pre|code>([\s\S]*?@[\s\S]*?)<\/(pre|code)>)/gi, function(wholeMatch, m1, m2, m3) {
return "<" + m1 + ">" + (m2.replace(/@/g, '&#64;')) + "</" + m3 + ">";
});
// add @username mentions, if valid; must be bounded on left and right by non-word characters