Skip to content

Commit

Permalink
fix: #274
Browse files Browse the repository at this point in the history
  • Loading branch information
taoqf committed May 14, 2024
1 parent 35b9f1f commit fef574d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/nodes/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,14 @@ export default class HTMLElement extends Node {
this.childNodes[o++] = node;
});
this.childNodes.length = o;

// remove whitespace between attributes
const attrs = Object.keys( this.rawAttributes).map((key) => {
const val = this.rawAttributes[key];
return `${key}=${ JSON.stringify(val)}`;
}).join(' ');
this.rawAttrs = attrs;
delete this._rawAttrs;
return this;
}

Expand Down
17 changes: 17 additions & 0 deletions test/tests/issues/274.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { parse } = require('@test/test-target');

describe('issue 274', function () {
it('removeWhitespace + outerHTML dont remove meaningless white-spaces inside start and end tags', function () {
const html = `<!DOCTYPE html
><html lang="en"
><meta charset="UTF-8"
><title>test</title
><p>test</p
></html>`;
const root = parse(html);
const el = root.querySelector('html').removeWhitespace();
el.outerHTML.should.eql('<html lang="en"><meta charset="UTF-8"><title>test</title><p>test</p></html>');
});
});
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"inlineSources": false,
"isolatedModules": false,
"lib": [
"esnext"
"esnext",
"dom"
],
"listFiles": false,
"listEmittedFiles": false,
Expand Down

0 comments on commit fef574d

Please sign in to comment.