« get me outta code hell

htmlify album pages - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util/html.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2022-07-02 15:21:24 -0300
committer(quasar) nebula <qznebula@protonmail.com>2022-07-02 15:21:24 -0300
commit9c11308ace82c024ddb0223d9ffeb742d86ad927 (patch)
tree8dd13e11c64b1e0a31b6a14b1e49a446a78c0921 /src/util/html.js
parent5e3042d2e37e835bffef477b4003aa323e1e66d8 (diff)
htmlify album pages prettify-lint
Diffstat (limited to 'src/util/html.js')
-rw-r--r--src/util/html.js19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/util/html.js b/src/util/html.js
index 0ba923b..338df71 100644
--- a/src/util/html.js
+++ b/src/util/html.js
@@ -20,11 +20,18 @@ export const selfClosingTags = [
   'wbr',
 ];
 
-// Pass to tag() as an attri8utes key to make tag() return a 8lank string
-// if the provided content is empty. Useful for when you'll only 8e showing
-// an element according to the presence of content that would 8elong there.
+// Pass to tag() as an attributes key to make tag() return a 8lank string if the
+// provided content is empty. Useful for when you'll only 8e showing an element
+// according to the presence of content that would 8elong there.
 export const onlyIfContent = Symbol();
 
+// Pass to tag() as an attributes key to make children be joined together by the
+// provided string. This is handy, for example, for joining lines by <br> tags,
+// or putting some other divider between each child. Note this will only have an
+// effect if the tag content is passed as an array of children and not a single
+// string.
+export const joinChildren = Symbol();
+
 export function tag(tagName, ...args) {
   const selfClosing = selfClosingTags.includes(tagName);
 
@@ -59,7 +66,11 @@ export function tag(tagName, ...args) {
   }
 
   if (Array.isArray(content)) {
-    content = content.filter(Boolean).join('\n');
+    const joiner = attrs?.[joinChildren];
+    content = content.filter(Boolean).join(
+      (joiner
+        ? `\n${joiner}\n`
+        : '\n'));
   }
 
   if (content) {