diff --git a/src/nodes/html.ts b/src/nodes/html.ts index 7df09eb..6fc810f 100644 --- a/src/nodes/html.ts +++ b/src/nodes/html.ts @@ -456,9 +456,9 @@ export default class HTMLElement extends Node { this.childNodes.length = o; // remove whitespace between attributes - const attrs = Object.keys( this.rawAttributes).map((key) => { + const attrs = Object.keys(this.rawAttributes).map((key) => { const val = this.rawAttributes[key]; - return `${key}=${ JSON.stringify(val)}`; + return `${key}=${JSON.stringify(val)}`; }).join(' '); this.rawAttrs = attrs; delete this._rawAttrs; @@ -959,8 +959,10 @@ export default class HTMLElement extends Node { } } +// #xB7 | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x203F-#x2040] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF] // https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name -const kMarkupPattern = /|<(\/?)([a-zA-Z][-.:0-9_a-zA-Z]*)((?:\s+[^>]*?(?:(?:'[^']*')|(?:"[^"]*"))?)*)\s*(\/?)>/g; +const kMarkupPattern = /|<(\/?)([a-zA-Z][-.:0-9_a-zA-Z@\xB7\xC0-\xD6\xD8-\xF6\u00F8-\u03A1\u03A3-\u03D9\u03DB-\u03EF\u03F7-\u03FF\u0400-\u04FF\u0500-\u052F\u1D00-\u1D2B\u1D6B-\u1D77\u1D79-\u1D9A\u1E00-\u1E9B\u1F00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2126\u212A-\u212B\u2132\u214E\u2160-\u2188\u2C60-\u2C7F\uA722-\uA787\uA78B-\uA78E\uA790-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA7FF\uAB30-\uAB5A\uAB5C-\uAB5F\uAB64-\uAB65\uFB00-\uFB06\uFB13-\uFB17\uFF21-\uFF3A\uFF41-\uFF5A\x37F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]*)((?:\s+[^>]*?(?:(?:'[^']*')|(?:"[^"]*"))?)*)\s*(\/?)>/gu; +// const kMarkupPattern = /|<(\/?)([a-zA-Z][-.:0-9_a-zA-Z]*)((?:\s+[^>]*?(?:(?:'[^']*')|(?:"[^"]*"))?)*)\s*(\/?)>/g; const kAttributePattern = /(?:^|\s)(id|class)\s*=\s*((?:'[^']*')|(?:"[^"]*")|\S+)/gi; const kElementsClosedByOpening = { li: { li: true, LI: true }, diff --git a/test/tests/issues/268.js b/test/tests/issues/268.js index 59e4edf..a7b7aad 100644 --- a/test/tests/issues/268.js +++ b/test/tests/issues/268.js @@ -25,7 +25,7 @@ describe.skip('issue 268', function () { const html = `xx`; const root = parse(html); const a = root.querySelector("a"); - console.error('sss',a.attributes); + console.error('sss', a.attributes); a.toString().should.eql('x'); // for (let tr of root.querySelectorAll("#mytable tr.myrow")) { // console.log('xxx',tr.querySelectorAll(":scope > td").map(e => e.innerText)); diff --git a/test/tests/issues/277.js b/test/tests/issues/277.js new file mode 100644 index 0000000..c2d0a4b --- /dev/null +++ b/test/tests/issues/277.js @@ -0,0 +1,38 @@ +const { parse } = require('@test/test-target'); + +describe('issue 277', function () { + it('custom tag name', function () { + const html = ` + + + test + + + + +`; + const root = parse(html); + const t = root.querySelector('template'); + const el = t.childNodes[1]; + el.toString().should.eql('Smile!'); + }); + it('unicode tag name', function () { + const html = ` + + + test + + + + +`; + const root = parse(html); + const t = root.querySelector('template'); + const el = t.childNodes[1]; + el.toString().should.eql('Smile!'); + }); +}); diff --git a/tsconfig.json b/tsconfig.json index 1955389..5865c8b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,7 @@ ], "compilerOptions": { "module": "commonjs", - "target": "es5", + "target": "es6", "noImplicitAny": true, "sourceMap": false, "emitDecoratorMetadata": true,