« get me outta code hell

html: #stringifyContent: always resolve template items - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-06-12 13:06:39 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-06-12 17:32:55 -0300
commitd6ff52b3f7d3096412a53116c49f5120a082cbf0 (patch)
treed71a51d0b15f57b6d7264addb5d5ca0346abf849
parentda2dbfdea3be32c5c277bb4c454d609f012a0472 (diff)
html: #stringifyContent: always resolve template items
This makes onlyIfSiblings on template content work properly.
It should also enable templates which return strings directly
to be treated as text for the purposes of chunkwrap, have own
blockwrap processed, etc.
-rw-r--r--src/util/html.js12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/util/html.js b/src/util/html.js
index 594966ed..6efedb31 100644
--- a/src/util/html.js
+++ b/src/util/html.js
@@ -649,10 +649,12 @@ export class Tag {
     }
 
     for (const [index, item] of contentItems.entries()) {
-      let itemContent;
+      const nonTemplateItem =
+        Template.resolve(item);
 
+      let itemContent;
       try {
-        itemContent = item.toString();
+        itemContent = nonTemplateItem.toString();
       } catch (caughtError) {
         const indexPart = colors.yellow(`child #${index + 1}`);
 
@@ -681,12 +683,12 @@ export class Tag {
         continue;
       }
 
-      if (!(item instanceof Tag && item.onlyIfSiblings)) {
+      if (!(nonTemplateItem instanceof Tag) || !nonTemplateItem.onlyIfSiblings) {
         seenSiblingIndependentContent = true;
       }
 
       const chunkwrapChunks =
-        (typeof item === 'string' && chunkwrapSplitter
+        (typeof nonTemplateItem === 'string' && chunkwrapSplitter
           ? itemContent.split(chunkwrapSplitter)
           : null);
 
@@ -726,7 +728,7 @@ export class Tag {
       // itemContent check. They also never apply at the very start of content,
       // because at that point there aren't any preceding words from which the
       // blockwrap would differentiate its content.
-      if (item instanceof Tag && item.blockwrap && content) {
+      if (nonTemplateItem instanceof Tag && nonTemplateItem.blockwrap && content) {
         content += `<span class="blockwrap">`;
         blockwrapClosers += `</span>`;
       }