diff --git a/app/assets/javascripts/discourse/dialects/bbcode_dialect.js b/app/assets/javascripts/discourse/dialects/bbcode_dialect.js
index 35390a8f3cd..b6cda69780a 100644
--- a/app/assets/javascripts/discourse/dialects/bbcode_dialect.js
+++ b/app/assets/javascripts/discourse/dialects/bbcode_dialect.js
@@ -144,17 +144,32 @@ Discourse.BBCode.rawBBCode('spoiler', function(contents) {
}
});
-Discourse.BBCode.register('url', function(contents, params) {
- if (!params) {
- if (contents && contents.length) {
- var tag = contents[0];
- if (tag && tag.length === 3 && tag[1].href) {
- return ['a', {'href': tag[1].href, 'data-bbcode': true}, tag[1].href];
- }
- }
- return;
+Discourse.BBCode.replaceBBCode('url', function(contents) {
+ if (!Array.isArray(contents)) { return; }
+ if (contents.length === 1 && contents[0][0] === 'a') {
+ // single-line bbcode links shouldn't be oneboxed, so we mark this as a bbcode link.
+ if (typeof contents[0][1] !== 'object') { contents[0].splice(1, 0, {}); }
+ contents[0][1]['data-bbcode'] = true;
}
- return ['a', {'href': params, 'data-bbcode': true}].concat(contents);
+ return ['concat'].concat(contents);
+});
+Discourse.BBCode.replaceBBCodeParamsRaw('url', function(param, contents) {
+ var url = param.replace(/(^")|("$)/g, '');
+ return ['a', {'href': url}].concat(this.processInline(contents));
+});
+Discourse.Dialect.on('parseNode', function(event) {
+ if (!Array.isArray(event.node)) { return; }
+ var result = [ event.node[0] ];
+ var nodes = event.node.slice(1);
+ var i, j;
+ for (i = 0; i < nodes.length; i++) {
+ if (Array.isArray(nodes[i]) && nodes[i][0] === 'concat') {
+ for (j = 1; j < nodes[i].length; j++) { result.push(nodes[i][j]); }
+ } else {
+ result.push(nodes[i]);
+ }
+ }
+ for (i = 0; i < result.length; i++) { event.node[i] = result[i]; }
});
Discourse.BBCode.replaceBBCodeParamsRaw("email", function(param, contents) {
diff --git a/test/javascripts/lib/bbcode-test.js.es6 b/test/javascripts/lib/bbcode-test.js.es6
index d3bff25cbdf..5ec3262ee81 100644
--- a/test/javascripts/lib/bbcode-test.js.es6
+++ b/test/javascripts/lib/bbcode-test.js.es6
@@ -16,7 +16,6 @@ test('basic bbcode', function() {
format("[u]underlined[/u]", "underlined", "underlines text");
format("[s]strikethrough[/s]", "strikethrough", "strikes-through text");
format("[img]http://eviltrout.com/eviltrout.png[/img]", "", "links images");
- format("[url]http://bettercallsaul.com[/url]", "http://bettercallsaul.com", "supports [url] without a title");
format("[email]eviltrout@mailinator.com[/email]", "eviltrout@mailinator.com", "supports [email] without a title");
format("[b]evil [i]trout[/i][/b]",
"evil trout",
@@ -25,7 +24,10 @@ test('basic bbcode', function() {
format("[b]strong [b]stronger[/b][/b]", "strong stronger", "accepts nested bbcode tags");
});
-test('url with images', function() {
+test('urls', function() {
+ format("[url]not a url[/url]", "not a url", "supports [url] that isn't a url");
+ format("[url]http://bettercallsaul.com[/url]", "http://bettercallsaul.com", "supports [url] without parameter");
+ format("[url=http://example.com]example[/url]", "example", "supports [url] with given href");
format("[url=http://www.example.com][img]http://example.com/logo.png[/img][/url]",
"",
"supports [url] with an embedded [img]");