Skip to content

Commit

Permalink
fixed SectionParser handling of paragraph following a list
Browse files Browse the repository at this point in the history
no issue
- if a `<p>` tag followed a list then then paragraph content was added to the final list item rather than breaking out of the list to create a new markup section
  • Loading branch information
kevinansfield committed Feb 13, 2019
1 parent 5578616 commit 892b66a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/js/parsers/section.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,12 @@ class SectionParser {
) {
// don't break out of the list for list items that contain a single <p>.
// deals with typical case of <li><p>Text</p></li><li><p>Text</p></li>
if (this.state.section.isListItem && tagName === 'p' && !node.nextSibling) {
if (
this.state.section.isListItem &&
tagName === 'p' &&
!node.nextSibling &&
contains(VALID_LIST_ITEM_TAGNAMES, normalizeTagName(node.parentElement.tagName))
) {
this.parseElementNode(node);
return;
}
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/parsers/section-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,24 @@ test('#parse doesn\'t group consecutive lists of different types', (assert) => {
assert.equal(ol.items.objectAt(0).text, 'Two');
});

test('#parse handles p following list', (assert) => {
let container = buildDOM(`
<div><ol><li>li1</li><li>li2</li><p>para</p></div>
`);

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

assert.equal(sections.length, 2, 'two sections');

let ol = sections[0];
assert.equal(ol.items.length, 2, 'two list items');

let p = sections[1];
assert.equal(p.text, 'para');
});

test('#parse skips STYLE nodes', (assert) => {
let element = buildDOM(`
<style>.rule { font-color: red; }</style>
Expand Down

0 comments on commit 892b66a

Please sign in to comment.