mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 10:41:45 +08:00
FIX: improve list bbcodes: ignore newlines resulting in unnecessary blank lines
This commit is contained in:
parent
79dc68512f
commit
b19ad15086
|
@ -55,6 +55,20 @@ function replaceBBCodeParamsRaw(tag, emitter) {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
Filters an array of JSON-ML nodes, removing nodes that represent empty lines ("\n").
|
||||
|
||||
@method removeEmptyLines
|
||||
@param {Array} [contents] Array of JSON-ML nodes
|
||||
**/
|
||||
function removeEmptyLines(contents) {
|
||||
var result = [];
|
||||
for (var i=0; i < contents.length; i++) {
|
||||
if (contents[i] !== "\n") { result.push(contents[i]); }
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a BBCode handler that accepts parameters. Passes them to the emitter.
|
||||
Processes the inside recursively so it can be nested.
|
||||
|
@ -75,9 +89,9 @@ replaceBBCode('u', function(contents) { return ['span', {'class': 'bbcode-u'}].c
|
|||
replaceBBCode('s', function(contents) { return ['span', {'class': 'bbcode-s'}].concat(contents); });
|
||||
Discourse.Markdown.whiteListTag('span', 'class', /^bbcode-[bius]$/);
|
||||
|
||||
replaceBBCode('ul', function(contents) { return ['ul'].concat(contents); });
|
||||
replaceBBCode('ol', function(contents) { return ['ol'].concat(contents); });
|
||||
replaceBBCode('li', function(contents) { return ['li'].concat(contents); });
|
||||
replaceBBCode('ul', function(contents) { return ['ul'].concat(removeEmptyLines(contents)); });
|
||||
replaceBBCode('ol', function(contents) { return ['ol'].concat(removeEmptyLines(contents)); });
|
||||
replaceBBCode('li', function(contents) { return ['li'].concat(removeEmptyLines(contents)); });
|
||||
|
||||
rawBBCode('img', function(contents) { return ['img', {href: contents}]; });
|
||||
rawBBCode('email', function(contents) { return ['a', {href: "mailto:" + contents, 'data-bbcode': true}, contents]; });
|
||||
|
|
|
@ -45,6 +45,7 @@ test('spoiler', function() {
|
|||
test('lists', function() {
|
||||
format("[ul][li]option one[/li][/ul]", "<ul><li>option one</li></ul>", "creates an ul");
|
||||
format("[ol][li]option one[/li][/ol]", "<ol><li>option one</li></ol>", "creates an ol");
|
||||
format("[ul]\n[li]option one[/li]\n[li]option two[/li]\n[/ul]", "<ul><li>option one</li><li>option two</li></ul>", "suppresses empty lines in lists");
|
||||
});
|
||||
|
||||
test('tags with arguments', function() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user