mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 21:53:51 +08:00
FIX: Don't onebox links with labels unless the labels are the same as the URL
This commit is contained in:
parent
c996378fc0
commit
a9f3489237
|
@ -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];
|
||||
}
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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",
|
||||
"<p><a href=\"http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street\" class=\"onebox\"" +
|
||||
">http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street</a></p>",
|
||||
|
|
Loading…
Reference in New Issue
Block a user