Skip to content

Commit

Permalink
handle parsing of lists when wrapped with indented html
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinansfield committed Mar 13, 2019
1 parent 333c293 commit ca8c6c5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/js/parsers/section.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,13 @@ class SectionParser {
trimSectionText(state.section);
lastSection.items.append(state.section);
} else {
// avoid creating empty markup sections, especially useful for indented source
if (state.section.isMarkerable && !state.section.text.trim()) {
state.section = null;
state.text = '';
return;
}

// remove empty list sections before creating a new section
if (lastSection && lastSection.isListSection && lastSection.items.length === 0) {
sections.pop();
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/parsers/section-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,29 @@ test('#parse handles insignificant whitespace', (assert) => {
assert.equal(list.items.objectAt(0).text, 'One');
});

test('#parse handles insignificant whitespace (wrapped)', (assert) => {
let container = buildDOM(`
<div>
<ul>
<li>
One
</li>
</ul>
</div>
`);

let element = container.firstChild;
parser = new SectionParser(builder);
let sections = parser.parse(element);

assert.equal(sections.length, 1, '1 section');
let [list] = sections;
assert.equal(list.type, 'list-section');
assert.equal(list.items.length, 1, '1 list item');
assert.equal(list.items.objectAt(0).text, 'One');
});


test('#parse avoids empty paragraph around wrapped list', (assert) => {
let container = buildDOM(`
<div><ul><li>One</li></ul></div>
Expand Down

0 comments on commit ca8c6c5

Please sign in to comment.