diff --git a/app/assets/javascripts/discourse/dialects/bbcode_dialect.js b/app/assets/javascripts/discourse/dialects/bbcode_dialect.js index 9cdb9de55be..a29b9c99eae 100644 --- a/app/assets/javascripts/discourse/dialects/bbcode_dialect.js +++ b/app/assets/javascripts/discourse/dialects/bbcode_dialect.js @@ -78,16 +78,23 @@ Discourse.Dialect.inlineBetween({ emitter: function(contents) { return ['a', {href: contents, 'data-bbcode': true}, contents]; } }); + Discourse.Dialect.inlineBetween({ start: '[spoiler]', stop: '[/spoiler]', rawContents: true, emitter: function(contents) { - if (/`, any other tags + // end up in a `span` + if (node.nodeType === 1 && node.nodeName === "IMG") { + return ['div', {class: 'spoiler'}, processInside(node)]; + } else { + return ['span', {class: 'spoiler'}, processInside(node)]; } }); diff --git a/app/assets/javascripts/discourse/dialects/dialect.js b/app/assets/javascripts/discourse/dialects/dialect.js index cf12fc64d1d..5be09d55914 100644 --- a/app/assets/javascripts/discourse/dialects/dialect.js +++ b/app/assets/javascripts/discourse/dialects/dialect.js @@ -22,6 +22,50 @@ function initializeDialects() { initialized = true; } +/** + Converts an HTML node Element into JsonML. + + @method nodeToJsonML + @param {Element} node to convert + @returns {Array} jsonML result +**/ +function nodeToJsonML(node) { + if (node.nodeType === 3) { + return node.nodeValue; + } + + var result = [node.nodeName.toLowerCase()], + attributes = {}; + + if (node.attributes && node.attributes.length > 0) { + for (var i=0; i" + expected + "

", text); + var cooked = Discourse.Markdown.cook(input, {lookupAvatar: false}).replace(/'/g, "\""); + equal(cooked, "

" + expected.replace(/'/g, "\"") + "

", text); }; test('basic bbcode', function() { @@ -30,8 +30,15 @@ test('code', function() { }); test('spoiler', function() { + format("[spoiler][/spoiler]", "", "it can spoil nothing"); format("[spoiler]it's a sled[/spoiler]", "it's a sled", "supports spoiler tags on text"); - format("[spoiler][/spoiler]", "
", "supports spoiler tags on images"); + format("[spoiler][/spoiler]", "
", "supports spoiler tags on images"); + format("foo bar[spoiler]aaa bbb[/spoiler]", + "foo baraaa
bbb", + "It wraps images and text differently in the same block"); + format("[spoiler]hello[/spoiler]", + "hello", + "It surrounds other HTML"); }); test('lists', function() {