« get me outta code hell

html: Tag.content: clean up contentArray compute - 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-04-12 15:16:12 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-04-12 15:16:12 -0300
commit7fff96a6dbd3858281b040e5cf4d7d86843f43d6 (patch)
treee547e3d26c4e8a6fa5446a73b43bb0c567ee1a5f /src/util
parent6933e233d5470ed6631650ef850979deb924d9ab (diff)
html: Tag.content: clean up contentArray compute
Diffstat (limited to 'src/util')
-rw-r--r--src/util/html.js18
1 files changed, 7 insertions, 11 deletions
diff --git a/src/util/html.js b/src/util/html.js
index 6f75e57a..f340f9ef 100644
--- a/src/util/html.js
+++ b/src/util/html.js
@@ -373,13 +373,12 @@ export class Tag {
       throw new Error(`Tag <${this.tagName}> is self-closing but got content`);
     }
 
-    let contentArray;
-
-    if (Array.isArray(value)) {
-      contentArray = value;
-    } else {
-      contentArray = [value];
-    }
+    const contentArray =
+      (Array.isArray(value)
+        ? value.flat(Infinity).filter(Boolean)
+     : value
+        ? [value]
+        : []);
 
     if (this.chunkwrap) {
       if (contentArray.some(content => content?.blockwrap)) {
@@ -387,10 +386,7 @@ export class Tag {
       }
     }
 
-    this.#content = contentArray
-      .flat(Infinity)
-      .filter(Boolean);
-
+    this.#content = contentArray;
     this.#content.toString = () => this.#stringifyContent();
   }