FIX: Nested quotes weren't rendered properly with BBCode

This commit is contained in:
Robin Ward 2017-04-03 14:38:30 -04:00
parent a13a8dc96c
commit 0829671963
3 changed files with 13 additions and 1 deletions

View File

@ -9,6 +9,8 @@ export function register(helper, codeName, args, emitter) {
start: new RegExp("\\[" + codeName + "(=[^\\[\\]]+)?\\]([\\s\\S]*)", "igm"),
stop: new RegExp("\\[\\/" + codeName + "\\]", "igm"),
emitter(blockContents, matches) {
const options = helper.getOptions();
while (blockContents.length && (typeof blockContents[0] === "string" || blockContents[0] instanceof String)) {
blockContents[0] = String(blockContents[0]).replace(/^\s+/, '');
@ -22,7 +24,11 @@ export function register(helper, codeName, args, emitter) {
let contents = [];
if (blockContents.length) {
const nextContents = blockContents.slice(1);
blockContents = this.processBlock(blockContents[0], nextContents).concat(nextContents);
blockContents = this.processBlock(blockContents[0], nextContents);
nextContents.forEach(nc => {
blockContents = blockContents.concat(this.processBlock(nc, []));
});
blockContents.forEach(bc => {
if (typeof bc === "string" || bc instanceof String) {

View File

@ -10,6 +10,7 @@ registerOption((siteSettings, opts) => {
export function setup(helper) {
register(helper, 'quote', {noWrap: true, singlePara: true}, (contents, bbParams, options) => {
const params = {'class': 'quote'};
let username = null;
const opts = helper.getOptions();

View File

@ -220,6 +220,11 @@ test("Quotes", function() {
"<p>1</p>\n\n<aside class=\"quote\" data-post=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>bob:" +
"</div><blockquote><p>my quote</p></blockquote></aside>\n\n<p>2</p>",
"includes no avatar if none is found");
cooked(`[quote]\na\n\n[quote]\nb\n[/quote]\n[/quote]`,
"<p><aside class=\"quote\"><blockquote><p>a</p><p><aside class=\"quote\"><blockquote><p>b</p></blockquote></aside></p></blockquote></aside></p>",
"handles nested quotes properly");
});
test("Mentions", function() {