preserve whitespace around custom fragments within `<pre>` (#885)
authorAlex Lam S.L <alexlamsl@gmail.com>
Thu, 15 Feb 2018 21:44:49 +0000 (05:44 +0800)
committerGitHub <noreply@github.com>
Thu, 15 Feb 2018 21:44:49 +0000 (05:44 +0800)
fixes #836

src/htmlminifier.js
tests/minifier.js

index df37d5c..4bdef7e 100644 (file)
@@ -1153,6 +1153,11 @@ function minify(value, options, partialMarkup) {
             trimTrailingWhitespace(buffer.length - 1, nextTag);
           }
         }
+        else if (uidPattern) {
+          text = text.replace(uidPattern, function(match, prefix, index) {
+            return ignoredCustomMarkupChunks[+index][0];
+          });
+        }
         if (!stackNoCollapseWhitespace.length && nextTag !== 'html' && !(prevTag && nextTag)) {
           text = collapseWhitespace(text, options, false, false, true);
         }
index c2bb274..f0979a5 100644 (file)
@@ -1918,6 +1918,10 @@ QUnit.test('Ignore custom fragments', function(assert) {
   input = '<link href="<?php echo \'http://foo/\' ?>">';
   assert.equal(minify(input), input);
   assert.equal(minify(input, { removeAttributeQuotes: true }), input);
+
+  input = '<pre>\nfoo\n<? bar ?>\nbaz\n</pre>';
+  assert.equal(minify(input), input);
+  assert.equal(minify(input, { collapseWhitespace: true }), input);
 });
 
 QUnit.test('bootstrap\'s span > button > span', function(assert) {