Skip to content

Commit fef574d

Browse files
committed
fix: #274
1 parent 35b9f1f commit fef574d

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/nodes/html.ts

+8
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,14 @@ export default class HTMLElement extends Node {
453453
this.childNodes[o++] = node;
454454
});
455455
this.childNodes.length = o;
456+
457+
// remove whitespace between attributes
458+
const attrs = Object.keys( this.rawAttributes).map((key) => {
459+
const val = this.rawAttributes[key];
460+
return `${key}=${ JSON.stringify(val)}`;
461+
}).join(' ');
462+
this.rawAttrs = attrs;
463+
delete this._rawAttrs;
456464
return this;
457465
}
458466

test/tests/issues/274.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const { parse } = require('@test/test-target');
2+
3+
describe('issue 274', function () {
4+
it('removeWhitespace + outerHTML dont remove meaningless white-spaces inside start and end tags', function () {
5+
const html = `<!DOCTYPE html
6+
><html lang="en"
7+
><meta charset="UTF-8"
8+
><title>test</title
9+
10+
><p>test</p
11+
12+
></html>`;
13+
const root = parse(html);
14+
const el = root.querySelector('html').removeWhitespace();
15+
el.outerHTML.should.eql('<html lang="en"><meta charset="UTF-8"><title>test</title><p>test</p></html>');
16+
});
17+
});

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"inlineSources": false,
3030
"isolatedModules": false,
3131
"lib": [
32-
"esnext"
32+
"esnext",
33+
"dom"
3334
],
3435
"listFiles": false,
3536
"listEmittedFiles": false,

0 commit comments

Comments
 (0)