correct bug where only a single poll per topic worked

This commit is contained in:
Sam 2017-06-28 15:36:19 -04:00
parent cfbda863e8
commit 6200d7d6ab
3 changed files with 39 additions and 1 deletions

View File

@ -227,7 +227,7 @@ function applyBBCode(state, startLine, endLine, silent, md) {
}
if (rule.after) {
rule.after.call(this, state, lastToken, md);
rule.after.call(this, state, lastToken, md, state.src.slice(start-2, start + closeTag.length - 1));
}
lastToken = state.tokens[state.tokens.length-1];

View File

@ -44,8 +44,18 @@ function getHelpText(count, min, max) {
function replaceToken(tokens, target, list) {
let pos = tokens.indexOf(target);
let level = tokens[pos].level;
tokens.splice(pos, 1, ...list);
list[0].map = target.map;
// resequence levels
for(;pos<tokens.length;pos++) {
let nesting = tokens[pos].nesting;
if (nesting < 0) { level--; }
tokens[pos].level = level;
if (nesting > 0) { level++; }
}
}
// analyzes the block to that we have poll options
@ -105,6 +115,9 @@ const rule = {
after: function(state, openToken, md, raw) {
let items = getListItems(state.tokens, openToken);
if (!items) {
return invalidPoll(state, raw);
}
const attrs = openToken.bbcode_attrs;
@ -190,6 +203,10 @@ const rule = {
replaceToken(state.tokens, openToken, header);
// we got to correct the level on the state
// we just resequenced
state.level = state.tokens[state.tokens.length-1].level;
state.push('poll_close', 'div', -1);
token = state.push('poll_open', 'div', 1);

View File

@ -12,6 +12,27 @@ describe PrettyText do
SiteSetting.enable_experimental_markdown_it = true
end
it 'can properly bake 2 polls' do
md = <<~MD
this is a test
- i am a list
[poll]
1. test 1
2. test 2
[/poll]
[poll name=poll2]
1. test 1
2. test 2
[/poll]
MD
cooked = PrettyText.cook(md)
expect(cooked.scan('class="poll"').length).to eq(2)
end
it 'works correctly for new vs old engine with trivial cases' do
md = <<~MD
[poll]