From 892b66a1a57a9608ad474566f7b13b898020f23f Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Wed, 13 Feb 2019 10:21:04 +0000 Subject: [PATCH] fixed SectionParser handling of paragraph following a list no issue - if a `

` 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 --- src/js/parsers/section.js | 7 ++++++- tests/unit/parsers/section-test.js | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/js/parsers/section.js b/src/js/parsers/section.js index c8c01a824..8d3a40563 100644 --- a/src/js/parsers/section.js +++ b/src/js/parsers/section.js @@ -191,7 +191,12 @@ class SectionParser { ) { // don't break out of the list for list items that contain a single

. // deals with typical case of

  • Text

  • Text

  • - 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; } diff --git a/tests/unit/parsers/section-test.js b/tests/unit/parsers/section-test.js index 497e1b368..67a58f456 100644 --- a/tests/unit/parsers/section-test.js +++ b/tests/unit/parsers/section-test.js @@ -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(` +
    1. li1
    2. li2
    3. para

    + `); + + 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(`