html-minifier-next 1.3.3 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -88,5 +88,5 @@
88
88
  "test:watch": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest --watch"
89
89
  },
90
90
  "type": "module",
91
- "version": "1.3.3"
91
+ "version": "1.4.0"
92
92
  }
@@ -260,7 +260,7 @@ function isSrcset(attrName, tag) {
260
260
  return attrName === 'srcset' && srcsetTags.has(tag);
261
261
  }
262
262
 
263
- async function cleanAttributeValue(tag, attrName, attrValue, options, attrs) {
263
+ async function cleanAttributeValue(tag, attrName, attrValue, options, attrs, minifyHTMLSelf) {
264
264
  if (isEventAttribute(attrName, options)) {
265
265
  attrValue = trimWhitespace(attrValue).replace(/^javascript:\s*/i, '');
266
266
  return options.minifyJS(attrValue, true);
@@ -318,6 +318,13 @@ async function cleanAttributeValue(tag, attrName, attrValue, options, attrs) {
318
318
  } else if (isMediaQuery(tag, attrs, attrName)) {
319
319
  attrValue = trimWhitespace(attrValue);
320
320
  return options.minifyCSS(attrValue, 'media');
321
+ } else if (tag === 'iframe' && attrName === 'srcdoc') {
322
+ // Recursively minify HTML content within srcdoc attribute
323
+ // Fast-path: skip if nothing would change
324
+ if (!shouldMinifyInnerHTML(options)) {
325
+ return attrValue;
326
+ }
327
+ return minifyHTMLSelf(attrValue, options, true);
321
328
  }
322
329
  return attrValue;
323
330
  }
@@ -557,7 +564,7 @@ async function normalizeAttr(attr, attrs, tag, options) {
557
564
  }
558
565
 
559
566
  if (attrValue) {
560
- attrValue = await cleanAttributeValue(tag, attrName, attrValue, options, attrs);
567
+ attrValue = await cleanAttributeValue(tag, attrName, attrValue, options, attrs, minifyHTML);
561
568
  }
562
569
 
563
570
  if (options.removeEmptyAttributes &&
@@ -632,6 +639,17 @@ function identityAsync(value) {
632
639
  return Promise.resolve(value);
633
640
  }
634
641
 
642
+ function shouldMinifyInnerHTML(options) {
643
+ return Boolean(
644
+ options.collapseWhitespace ||
645
+ options.removeComments ||
646
+ options.removeOptionalTags ||
647
+ options.minifyJS !== identity ||
648
+ options.minifyCSS !== identityAsync ||
649
+ options.minifyURLs !== identity
650
+ );
651
+ }
652
+
635
653
  const processOptions = (inputOptions) => {
636
654
  const options = {
637
655
  name: function (name) {