« get me outta code hell

html: smush, chunkwrap: always handle joiners manually - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
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
commit5da9b999aea8adb57edfa9526a602cfe5cb2f066 (patch)
treed0dd72ef5402c607135ba3dd2da8556cb4b9c0e9 /src
parent7e1bac49bcac96d7fee9348248974576f94db194 (diff)
html: smush, chunkwrap: always handle joiners manually
Diffstat (limited to 'src')
-rw-r--r--src/util/html.js25
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);
   }