diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-03-26 10:27:31 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-03-26 10:27:31 -0300 |
commit | 5da9b999aea8adb57edfa9526a602cfe5cb2f066 (patch) | |
tree | d0dd72ef5402c607135ba3dd2da8556cb4b9c0e9 | |
parent | 7e1bac49bcac96d7fee9348248974576f94db194 (diff) |
html: smush, chunkwrap: always handle joiners manually
-rw-r--r-- | src/util/html.js | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/util/html.js b/src/util/html.js index f59f9192..b8dea516 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); } |