瀏覽代碼

don't collapse \n and space, \t \f \r chars together

Gildas 7 年之前
父節點
當前提交
fd4693be30
共有 1 個文件被更改,包括 6 次插入1 次删除
  1. 6 1
      lib/single-file/htmlmini.js

+ 6 - 1
lib/single-file/htmlmini.js

@@ -197,11 +197,16 @@ this.htmlmini = this.htmlmini || (() => {
 				noWhitespace = element && noWhitespaceCollapse(element);
 			}
 			if ((!element || noWhitespace) && textContent.length > 1) {
-				node.textContent = textContent.replace(/[ \t\n\f\r]+/g, node.parentElement && node.parentElement.tagName == "HEAD" ? "\n" : " ");
+				node.textContent = textContent.replace(/[ \t\f\r]+/g, getWhiteSpace(node));
+				node.textContent = textContent.replace(/[\n]+/g, getWhiteSpace(node));
 			}
 		}
 	}
 
+	function getWhiteSpace(node) {
+		return node.parentElement && node.parentElement.tagName == "HEAD" ? "\n" : " ";
+	}
+
 	function noWhitespaceCollapse(element) {
 		return element && !noWhitespaceCollapseElements.includes(element.tagName.toLowerCase());
 	}