diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2022-07-13 00:34:36 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2022-07-13 00:34:36 -0300 |
commit | 474e8afe7328b80cda5e437e1d1b8c1191425d72 (patch) | |
tree | 3eefd1d8a75e95f99890a9f2484da6e7436c4c9b /src/util | |
parent | b6b8be24a705d0c9d710066751480304dd64d758 (diff) |
begin htmlifying listings & listing specs
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/html.js | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/util/html.js b/src/util/html.js index 338df71b..bdb385b5 100644 --- a/src/util/html.js +++ b/src/util/html.js @@ -55,7 +55,7 @@ export function tag(tagName, ...args) { } if (attrs) { - const attrString = attributes(args[0]); + const attrString = attributes(attrs); if (attrString) { openTag = `${tagName} ${attrString}`; } @@ -121,3 +121,19 @@ export function attributes(attribs) { ) .join(' '); } + +// Ensures the passed value is an array of elements, for usage in [...spread] +// syntax. This may be used when it's not guaranteed whether the return value of +// an external function is one child or an array, or in combination with +// conditionals, e.g. fragment(cond && [x, y, z]). +export function fragment(childOrChildren) { + if (!childOrChildren) { + return []; + } + + if (Array.isArray(childOrChildren)) { + return childOrChildren; + } + + return [childOrChildren]; +} |