Browse Source

stricter rule regarding omission of </li>

Gildas 7 years ago
parent
commit
cb298a6da0
1 changed files with 2 additions and 2 deletions
  1. 2 2
      lib/single-file/modules/html-serializer.js

+ 2 - 2
lib/single-file/modules/html-serializer.js

@@ -33,7 +33,7 @@ this.serializer = this.serializer || (() => {
 		{ tagName: "html", accept: next => !next || next.nodeType != Node.COMMENT_NODE },
 		{ tagName: "head", accept: next => !next || (next.nodeType != Node.COMMENT_NODE && (next.nodeType != Node.TEXT_NODE || !startsWithSpaceChar(next.textContent))) },
 		{ tagName: "body", accept: next => !next || next.nodeType != Node.COMMENT_NODE },
-		{ tagName: "li", accept: next => !next || ["LI"].includes(next.tagName) },
+		{ tagName: "li", accept: (next, element) => (!next && element.parentElement && (element.parentElement.tagName == "UL" || element.parentElement.tagName == "OL")) || (next && ["LI"].includes(next.tagName)) },
 		{ tagName: "dt", accept: next => !next || ["DT", "DD"].includes(next.tagName) },
 		{ tagName: "p", accept: next => next && ["ADDRESS", "ARTICLE", "ASIDE", "BLOCKQUOTE", "DETAILS", "DIV", "DL", "FIELDSET", "FIGCAPTION", "FIGURE", "FOOTER", "FORM", "H1", "H2", "H3", "H4", "H5", "H6", "HEADER", "HR", "MAIN", "NAV", "OL", "P", "PRE", "SECTION", "TABLE", "UL"].includes(next.tagName) },
 		{ tagName: "dd", accept: next => !next || ["DT", "DD"].includes(next.tagName) },
@@ -112,7 +112,7 @@ this.serializer = this.serializer || (() => {
 			content += ">";
 		}
 		Array.from(element.childNodes).forEach(childNode => content += serialize(childNode));
-		const omittedEndTag = OMITTED_END_TAGS.find(omittedEndTag => tagName == omittedEndTag.tagName && omittedEndTag.accept(element.nextSibling));
+		const omittedEndTag = OMITTED_END_TAGS.find(omittedEndTag => tagName == omittedEndTag.tagName && omittedEndTag.accept(element.nextSibling, element));
 		if (!omittedEndTag && !SELF_CLOSED_TAG_NAMES.includes(tagName)) {
 			content += "</" + tagName + ">";
 		}