« get me outta code hell

html: don't show onlyIfSiblings items w/o siblings - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-06-07 16:01:24 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-06-07 16:03:42 -0300
commit131378833ac493d009ebe2f85af7e955deba0530 (patch)
tree35e2044cc380d2455d3a97ff98023019667552ac /src/util
parent4d233b35254b3e810de6f2f55fe83bc58b8c16f4 (diff)
html: don't show onlyIfSiblings items w/o siblings
Previous commits are A-OK for making html.isBlank() work properly
with [html.onlyIfSiblings] tags - and consequently, parent tags
with [html.onlyIfContent] - but if the parent *doesn't* have this
attribute, it needs to take responsibility in its own toString /
function.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/html.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/util/html.js b/src/util/html.js
index 310e5a76..6e892031 100644
--- a/src/util/html.js
+++ b/src/util/html.js
@@ -617,6 +617,8 @@ export class Tag {
     let content = '';
     let blockwrapClosers = '';
 
+    let seenSiblingIndependentContent = false;
+
     const chunkwrapSplitter =
       (this.chunkwrap
         ? this.#getAttributeString('split')
@@ -671,6 +673,10 @@ export class Tag {
         continue;
       }
 
+      if (!(item instanceof Tag && item.onlyIfSiblings)) {
+        seenSiblingIndependentContent = true;
+      }
+
       const chunkwrapChunks =
         (typeof item === 'string' && chunkwrapSplitter
           ? itemContent.split(chunkwrapSplitter)
@@ -743,6 +749,12 @@ export class Tag {
       }
     }
 
+    // If we've only seen sibling-dependent content (or just no content),
+    // then the content in total is blank.
+    if (!seenSiblingIndependentContent) {
+      return '';
+    }
+
     if (chunkwrapSplitter) {
       if (seenChunkwrapSplitter) {
         content += '</span>';