Skip to content

Commit

Permalink
do not group consecutive list sections of different types
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinansfield committed Jan 16, 2019
1 parent 66d2120 commit 45e4d27
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/js/parsers/section.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class SectionParser {
return false;
}

/* eslint-disable complexity */
parseNode(node) {
if (!this.state.section) {
this._updateStateFromElement(node);
Expand All @@ -143,12 +144,24 @@ class SectionParser {
// new-section-creating element.
if (this.state.section && !isTextNode(node) && node.tagName) {
let tagName = normalizeTagName(node.tagName);
let isNestedListSection = contains(VALID_LIST_SECTION_TAGNAMES, tagName)

let isListSection = contains(VALID_LIST_SECTION_TAGNAMES, tagName);
let isNestedListSection = isListSection
&& this.state.section.isListItem;

// if we have consecutive list sections of different types (ul, ol) then
// ensure we close the current section and start a new one
let lastSection = this.sections[this.sections.length - 1];
let isNewListSection = lastSection
&& lastSection.isListSection
&& this.state.section.isListItem
&& isListSection
&& tagName !== lastSection.tagName;

if (
isNewListSection ||
(isListSection && !isNestedListSection) ||
contains(VALID_MARKUP_SECTION_TAGNAMES, tagName) ||
(contains(VALID_LIST_SECTION_TAGNAMES, tagName) && !isNestedListSection) ||
contains(VALID_LIST_ITEM_TAGNAMES, tagName)
) {
// don't break out of the list for list items that contain a single <p>.
Expand Down

0 comments on commit 45e4d27

Please sign in to comment.