From 8c80d75518accbe9c98b34b78edae1a1725f00e5 Mon Sep 17 00:00:00 2001 From: Sibiraj <20282546+sibiraj-s@users.noreply.github.com> Date: Mon, 1 Dec 2025 17:31:49 +0530 Subject: [PATCH] Option to skip attribute normalization --- README.md | 1 + src/htmlminifier.js | 11 ++++++++++- tests/minifier.spec.js | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index aee347c..12660d0 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,7 @@ Most of the options are disabled by default. | `sortClassName` | [Sort style classes by frequency](#sorting-attributes--style-classes) | `false` | | `trimCustomFragments` | Trim white space around `ignoreCustomFragments`. | `false` | | `useShortDoctype` | [Replaces the `doctype` with the short (HTML5) doctype](http://perfectionkills.com/experimenting-with-html-minifier#use_short_doctype) | `false` | +| `normalizeAttributes` | Normalize attributes | `true` | ### Sorting attributes / style classes diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 6e442fd..5ba2479 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -542,6 +542,14 @@ function canTrimWhitespace(tag) { } async function normalizeAttr(attr, attrs, tag, options) { + if (!options.normalizeAttributes) { + return { + attr, + name: attr.name, + value: attr.value + }; + } + const attrName = options.name(attr.name); let attrValue = attr.value; @@ -654,7 +662,8 @@ const processOptions = (inputOptions) => { log: identity, minifyCSS: identityAsync, minifyJS: identity, - minifyURLs: identity + minifyURLs: identity, + normalizeAttributes: true, }; Object.keys(inputOptions).forEach(function (key) { diff --git a/tests/minifier.spec.js b/tests/minifier.spec.js index a299557..570e0f1 100644 --- a/tests/minifier.spec.js +++ b/tests/minifier.spec.js @@ -175,6 +175,12 @@ test('space normalization between attributes', async () => { expect(await minify('')).toBe(''); }); +test('not normalize attributes', async () => { + expect(await minify('
foo
', { normalizeAttributes: false })).toBe('foo
'); + expect(await minify('blah
\n\n\n ';