New API for replacing elements in the final JsonML. Also changes spoiler

tag handling to be more robust with repsect to HTML content.
This commit is contained in:
Robin Ward
2014-01-20 15:09:05 -05:00
parent 2d98720cc8
commit 6b9b2d3d6a
3 changed files with 92 additions and 8 deletions
@@ -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 (/<img/i.test(contents)) {
return ['div', { 'class': 'spoiler' }, contents];
} else {
return ['span', { 'class': 'spoiler' }, contents];
}
return ["__spoiler", this.processInline(contents)];
}
});
Discourse.Dialect.replaceElement('__spoiler', function(node, processInside) {
// Surround images with a `<div class='spoiler'>`, 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)];
}
});