From 5da9b999aea8adb57edfa9526a602cfe5cb2f066 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 26 Mar 2024 10:27:31 -0300 Subject: html: smush, chunkwrap: always handle joiners manually --- src/util/html.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/util/html.js b/src/util/html.js index f59f919..b8dea51 100644 --- a/src/util/html.js +++ b/src/util/html.js @@ -477,6 +477,13 @@ export class Tag { } get joinChildren() { + // A chunkwrap - which serves as the top layer of a smush() when + // stringifying that chunkwrap - is only meant to be an invisible + // layer, so its own children are never specially joined. + if (this.chunkwrap) { + return ''; + } + return this.#getAttributeString(joinChildren); } @@ -746,6 +753,13 @@ export class Tag { const joiner = this.#getContentJoiner(); const result = []; + const attributes = {}; + + // Don't use built-in item joining, since we'll be handling it here - + // we need to account for descendants having custom joiners too, and + // simply using *this* tag's joiner would overwrite those descendants' + // differing joiners. + attributes[joinChildren] = ''; let workingText = ''; @@ -770,10 +784,15 @@ export class Tag { } if (workingText) { - result.push(workingText); + result.push(workingText + joiner); + } else if (!empty(result)) { + result.push(joiner); } if (typeof smushedItems.at(-1) === 'string') { + // The last smushed item already had its joiner processed from its own + // parent - this isn't an appropriate place for us to insert our own + // joiner. workingText = smushedItems.pop(); } else { workingText = ''; @@ -786,10 +805,6 @@ export class Tag { result.push(workingText); } - const attributes = { - [joinChildren]: this.joinChildren, - }; - return new Tag(null, attributes, result); } -- cgit 1.3.0-6-gf8a5