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
6 changes: 5 additions & 1 deletion cjs/html/text-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ class TextElement extends HTMLElement {

toString() {
const outerHTML = toString.call(this.cloneNode());
return outerHTML.replace('><', () => `>${this.textContent}<`);
/* c8 ignore next */
if (outerHTML.endsWith(' />')) return outerHTML; // self-closed, as in XML documents
// the text goes before the end tag, as attribute values can contain "></" too
const end = outerHTML.lastIndexOf('></') + 1;
return outerHTML.slice(0, end) + this.textContent + outerHTML.slice(end);
}
}
exports.TextElement = TextElement
6 changes: 5 additions & 1 deletion esm/html/text-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export class TextElement extends HTMLElement {

toString() {
const outerHTML = toString.call(this.cloneNode());
return outerHTML.replace('><', () => `>${this.textContent}<`);
/* c8 ignore next */
if (outerHTML.endsWith(' />')) return outerHTML; // self-closed, as in XML documents
// the text goes before the end tag, as attribute values can contain "></" too
const end = outerHTML.lastIndexOf('></') + 1;
return outerHTML.slice(0, end) + this.textContent + outerHTML.slice(end);
}
}
6 changes: 5 additions & 1 deletion worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8482,7 +8482,11 @@ class TextElement extends HTMLElement {

toString() {
const outerHTML = toString.call(this.cloneNode());
return outerHTML.replace('><', () => `>${this.textContent}<`);
/* c8 ignore next */
if (outerHTML.endsWith(' />')) return outerHTML; // self-closed, as in XML documents
// the text goes before the end tag, as attribute values can contain "></" too
const end = outerHTML.lastIndexOf('></') + 1;
return outerHTML.slice(0, end) + this.textContent + outerHTML.slice(end);
}
}

Expand Down