Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 10 additions & 1 deletion src/htmlminifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions tests/minifier.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ test('space normalization between attributes', async () => {
expect(await minify('<input title="bar" id="boo" value="hello world">')).toBe('<input title="bar" id="boo" value="hello world">');
});

test('not normalize attributes', async () => {
expect(await minify('<p title="bar">foo</p>', { normalizeAttributes: false })).toBe('<p title="bar">foo</p>');
expect(await minify('<img src="test"/>', { normalizeAttributes: false })).toBe('<img src="test">');
expect(await minify('<img src=" test "/>', { normalizeAttributes: false })).toBe('<img src=" test ">');
});

test('space normalization around text', async () => {
let input, output;
input = ' <p>blah</p>\n\n\n ';
Expand Down