Explorar el Código

fixed whitespace collapsing issue

Gildas hace 7 años
padre
commit
adf9f582b8
Se han modificado 2 ficheros con 12 adiciones y 9 borrados
  1. 10 8
      lib/single-file/modules/html-minifier.js
  2. 2 1
      lib/single-file/util/doc-util.js

+ 10 - 8
lib/single-file/modules/html-minifier.js

@@ -190,14 +190,16 @@ this.htmlMinifier = this.htmlMinifier || (() => {
 		if (node.nodeType == Node_TEXT_NODE) {
 			let element = node.parentElement;
 			const spacePreserved = element.getAttribute(options.PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME) == "";
-			const textContent = node.textContent;
-			let noWhitespace = !spacePreserved && noWhitespaceCollapse(element);
-			while (noWhitespace) {
-				element = element.parentElement;
-				noWhitespace = element && noWhitespaceCollapse(element);
-			}
-			if ((!element || noWhitespace) && textContent.length > 1) {
-				node.textContent = textContent.replace(REGEXP_WHITESPACE, getWhiteSpace(node)).replace(REGEXP_NEWLINE, "\n");
+			if (!spacePreserved) {
+				const textContent = node.textContent;
+				let noWhitespace = noWhitespaceCollapse(element);
+				while (noWhitespace) {
+					element = element.parentElement;
+					noWhitespace = element && noWhitespaceCollapse(element);
+				}
+				if ((!element || noWhitespace) && textContent.length > 1) {
+					node.textContent = textContent.replace(REGEXP_WHITESPACE, getWhiteSpace(node)).replace(REGEXP_NEWLINE, "\n");
+				}
 			}
 		}
 	}

+ 2 - 1
lib/single-file/util/doc-util.js

@@ -130,7 +130,8 @@ this.docUtil = this.docUtil || (() => {
 				REMOVED_CONTENT_ATTRIBUTE_NAME: modules.docHelper.REMOVED_CONTENT_ATTRIBUTE_NAME,
 				IMAGE_ATTRIBUTE_NAME: modules.docHelper.IMAGE_ATTRIBUTE_NAME,
 				INPUT_VALUE_ATTRIBUTE_NAME: modules.docHelper.INPUT_VALUE_ATTRIBUTE_NAME,
-				SHADOW_ROOT_ATTRIBUTE_NAME: modules.docHelper.SHADOW_ROOT_ATTRIBUTE_NAME
+				SHADOW_ROOT_ATTRIBUTE_NAME: modules.docHelper.SHADOW_ROOT_ATTRIBUTE_NAME,
+				PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME: modules.docHelper.PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME
 			};
 
 			async function getContent(resourceURL, options) {