« get me outta code hell

data steps: test cases for new html implementation - 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>2023-03-21 19:51:25 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-03-21 19:51:25 -0300
commit680681f89b5e3d89d953421eb4aabed7ba46d78d (patch)
treef167fff9943fcb0adc0f5ac4b4e99c7009337fec /src
parent0d94a61ea4797ef77f4a9214b9b4322fc8bf9942 (diff)
data steps: test cases for new html implementation
Only Tag interface and stringification for now.
Template tests coming soon!
Diffstat (limited to 'src')
-rw-r--r--src/util/html.js10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/util/html.js b/src/util/html.js
index cb4a84e..3f89a28 100644
--- a/src/util/html.js
+++ b/src/util/html.js
@@ -107,7 +107,13 @@ export class Tag {
   }
 
   set content(value) {
-    if (this.selfClosing) {
+    if (
+      this.selfClosing &&
+      !(value === null ||
+        value === undefined ||
+        !Boolean(value) ||
+        Array.isArray(value) && value.filter(Boolean).length === 0)
+    ) {
       throw new Error(`Tag <${this.tagName}> is self-closing but got content`);
     }
 
@@ -331,7 +337,7 @@ export class Attributes {
         else if (typeof val === 'number')
           return [key, val.toString(), true];
         else if (Array.isArray(val))
-          return [key, val.filter(Boolean).join(' '), keep ?? val.length > 0];
+          return [key, val.filter(Boolean).join(' '), val.length > 0];
         else
           throw new Error(`Attribute value for ${key} should be primitive or array, got ${typeof val}`);
       })