From 131378833ac493d009ebe2f85af7e955deba0530 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 7 Jun 2024 16:01:24 -0300 Subject: 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. --- src/util/html.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 += ''; -- cgit 1.3.0-6-gf8a5