Просмотр исходного кода

fixed startsWithSpaceChar function

Gildas 7 лет назад
Родитель
Сommit
7ad3b3b27f
1 измененных файлов с 5 добавлено и 5 удалено
  1. 5 5
      lib/single-file/serializer.js

+ 5 - 5
lib/single-file/serializer.js

@@ -32,7 +32,7 @@ this.serializer = this.serializer || (() => {
 	];
 	const OMITTED_END_TAGS = [
 		{ 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 || !spaceFirstCharacter(next.textContent)) },
+		{ 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: "dt", accept: next => !next || ["DT", "DD"].includes(next.tagName) },
@@ -42,8 +42,8 @@ this.serializer = this.serializer || (() => {
 		{ tagName: "rp", accept: next => !next || ["RT", "RP"].includes(next.tagName) },
 		{ tagName: "optgroup", accept: next => !next || ["OPTGROUP"].includes(next.tagName) },
 		{ tagName: "option", accept: next => !next || ["OPTION", "OPTGROUP"].includes(next.tagName) },
-		{ tagName: "colgroup", accept: next => !next || next.nodeType != Node.COMMENT_NODE && (next.nodeType != Node.TEXT_NODE || !spaceFirstCharacter(next.textContent)) },
-		{ tagName: "caption", accept: next => !next || next.nodeType != Node.COMMENT_NODE && (next.nodeType != Node.TEXT_NODE || !spaceFirstCharacter(next.textContent)) },
+		{ tagName: "colgroup", accept: next => !next || next.nodeType != Node.COMMENT_NODE && (next.nodeType != Node.TEXT_NODE || !startsWithSpaceChar(next.textContent)) },
+		{ tagName: "caption", accept: next => !next || next.nodeType != Node.COMMENT_NODE && (next.nodeType != Node.TEXT_NODE || !startsWithSpaceChar(next.textContent)) },
 		{ tagName: "thead", accept: next => !next || ["TBODY", "TFOOT"].includes(next.tagName) },
 		{ tagName: "tbody", accept: next => !next || ["TBODY", "TFOOT"].includes(next.tagName) },
 		{ tagName: "tfoot", accept: next => !next },
@@ -150,8 +150,8 @@ this.serializer = this.serializer || (() => {
 		return content;
 	}
 
-	function spaceFirstCharacter(textContent) {
-		return Boolean(textContent.charAt(0).match(/ \t\n\f\r+/));
+	function startsWithSpaceChar(textContent) {
+		return Boolean(textContent.match(/^[ \t\n\f\r]/));
 	}
 
 })();