mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
FIX: Allow BBCode images within BBCode links
This commit is contained in:
parent
384d8f25e4
commit
914217f78a
2 changed files with 16 additions and 3 deletions
|
@ -136,7 +136,6 @@ Discourse.BBCode.replaceBBCode('li', function(contents) { return ['li'].concat(D
|
|||
|
||||
Discourse.BBCode.rawBBCode('img', function(contents) { return ['img', {href: contents}]; });
|
||||
Discourse.BBCode.rawBBCode('email', function(contents) { return ['a', {href: "mailto:" + contents, 'data-bbcode': true}, contents]; });
|
||||
Discourse.BBCode.rawBBCode('url', function(contents) { return ['a', {href: contents, 'data-bbcode': true}, contents]; });
|
||||
Discourse.BBCode.rawBBCode('spoiler', function(contents) {
|
||||
if (/<img/i.test(contents)) {
|
||||
return ['div', { 'class': 'spoiler' }, contents];
|
||||
|
@ -145,8 +144,17 @@ Discourse.BBCode.rawBBCode('spoiler', function(contents) {
|
|||
}
|
||||
});
|
||||
|
||||
Discourse.BBCode.replaceBBCodeParamsRaw("url", function(param, contents) {
|
||||
return ['a', {href: param, 'data-bbcode': true}].concat(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;
|
||||
}
|
||||
return ['a', {'href': params, 'data-bbcode': true}].concat(contents);
|
||||
});
|
||||
|
||||
Discourse.BBCode.replaceBBCodeParamsRaw("email", function(param, contents) {
|
||||
|
|
|
@ -25,6 +25,11 @@ test('basic bbcode', function() {
|
|||
format("[b]strong [b]stronger[/b][/b]", "<span class=\"bbcode-b\">strong <span class=\"bbcode-b\">stronger</span></span>", "accepts nested bbcode tags");
|
||||
});
|
||||
|
||||
test('url with images', function() {
|
||||
format("[url=http://www.example.com][img]http://example.com/logo.png[/img][/url]",
|
||||
"<a href=\"http://www.example.com\"><img src=\"http://example.com/logo.png\"></a>",
|
||||
"supports [url] with an embedded [img]");
|
||||
});
|
||||
test('invalid bbcode', function() {
|
||||
var cooked = Discourse.Markdown.cook("[code]I am not closed\n\nThis text exists.", {lookupAvatar: false});
|
||||
equal(cooked, "<p>[code]I am not closed</p>\n\n<p>This text exists.</p>", "does not raise an error with an open bbcode tag.");
|
||||
|
|
Loading…
Reference in a new issue