diff --git a/app/assets/javascripts/discourse/dialects/autolink_dialect.js b/app/assets/javascripts/discourse/dialects/autolink_dialect.js index 8917939d1b4..85caabb7053 100644 --- a/app/assets/javascripts/discourse/dialects/autolink_dialect.js +++ b/app/assets/javascripts/discourse/dialects/autolink_dialect.js @@ -10,6 +10,9 @@ var urlReplacerArgs = { var url = matches[1], displayUrl = url; + // If we improperly caught a markdown link abort + if (url.match(/\(http/)) { return; } + if (url.match(/^www/)) { url = "http://" + url; } return ['a', {href: url}, displayUrl]; } diff --git a/app/assets/javascripts/discourse/dialects/onebox_dialect.js b/app/assets/javascripts/discourse/dialects/onebox_dialect.js index 4c4ebd38986..8939cdab0e4 100644 --- a/app/assets/javascripts/discourse/dialects/onebox_dialect.js +++ b/app/assets/javascripts/discourse/dialects/onebox_dialect.js @@ -57,7 +57,12 @@ Discourse.Dialect.on("parseNode", function(event) { if (path[i][0] === 'li') { return; } } + // If the link has a different label text than the link itself, don't onebox it. + var label = node[node.length-1]; + if (label !== node[1]['href']) { return; } + if (isOnOneLine(node, parent)) { + node[1]['class'] = 'onebox'; node[1].target = '_blank'; diff --git a/test/javascripts/components/markdown_test.js b/test/javascripts/components/markdown_test.js index f9425009e3f..a27e7dca9a5 100644 --- a/test/javascripts/components/markdown_test.js +++ b/test/javascripts/components/markdown_test.js @@ -217,6 +217,11 @@ test("Oneboxing", function() { ok(matches("http://test.com\nhttp://test2.com", /onebox[\s\S]+onebox/m), "supports multiple links"); ok(!matches("http://test.com bob", /onebox/), "doesn't onebox links that have trailing text"); + ok(!matches("[Tom Cruise](http://www.tomcruise.com/)", "onebox"), "Markdown links with labels are not oneboxed"); + ok(matches("[http://www.tomcruise.com/](http://www.tomcruise.com/)", + "onebox"), + "Markdown links where the label is the same as the url are oneboxed"); + cooked("http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street", "
",