diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2022-11-28 20:25:47 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2022-11-28 20:25:47 -0400 |
commit | ae9dba60c4bbb327b402c500cc042922a954de74 (patch) | |
tree | 81084937a13778104c29976e027e83a17c51f5fb /src/util | |
parent | 5206ac7188c9eefd6f1d18050e2831b0f10be8ef (diff) |
chronology tweaks & html.onlyIfContent bugfix
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/html.js | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/src/util/html.js b/src/util/html.js index 6c429b92..a6b0d621 100644 --- a/src/util/html.js +++ b/src/util/html.js @@ -56,6 +56,18 @@ export function tag(tagName, ...args) { throw new Error(`Tag <${tagName}> is self-closing but got content!`); } + if (Array.isArray(content)) { + if (content.some(item => Array.isArray(item))) { + throw new Error(`Found array instead of string (tag) or null/falsey, did you forget to \`...\` spread an array or fragment?`); + } + + const joiner = attrs?.[joinChildren]; + content = content.filter(Boolean).join( + (joiner + ? `\n${joiner}\n` + : '\n')); + } + if (attrs?.[onlyIfContent] && !content) { return ''; } @@ -71,18 +83,6 @@ export function tag(tagName, ...args) { openTag = tagName; } - if (Array.isArray(content)) { - if (content.some(item => Array.isArray(item))) { - throw new Error(`Found array instead of string (tag) or null/falsey, did you forget to \`...\` spread an array or fragment?`); - } - - const joiner = attrs?.[joinChildren]; - content = content.filter(Boolean).join( - (joiner - ? `\n${joiner}\n` - : '\n')); - } - if (content) { if (content.includes('\n')) { return [ @@ -102,12 +102,10 @@ export function tag(tagName, ...args) { } else { return `<${openTag}>${content}</${tagName}>`; } + } else if (selfClosing) { + return `<${openTag}>`; } else { - if (selfClosing) { - return `<${openTag}>`; - } else { - return `<${openTag}></${tagName}>`; - } + return `<${openTag}></${tagName}>`; } } |