« get me outta code hell

html: html.smooth() - 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>2024-04-30 17:24:55 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-01 20:22:37 -0300
commitf6a103f52abc42eaeba29b7bbfcd9c622f043154 (patch)
treeec6c3c7e7f368276894e54e2f157aea0a1b6e3f3 /src
parentc8c9c465b241062570cc3955c01fb5d59d20d888 (diff)
html: html.smooth()
Diffstat (limited to 'src')
-rw-r--r--src/util/html.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/util/html.js b/src/util/html.js
index d1d509e..0f190e2 100644
--- a/src/util/html.js
+++ b/src/util/html.js
@@ -1338,6 +1338,22 @@ export function smush(smushee) {
   return smush(Tag.normalize(smushee));
 }
 
+// Much gentler version of smush - this only flattens nested html.tags(), and
+// guarantees the result is itself an html.tags(). It doesn't manipulate text
+// content, and it doesn't resolve templates.
+export function smooth(smoothie) {
+  // Helper function to avoid intermediate html.tags() calls.
+  function helper(tag) {
+    if (tag instanceof Tag && tag.contentOnly) {
+      return tag.content.flatMap(helper);
+    } else {
+      return tag;
+    }
+  }
+
+  return tags(helper(smoothie));
+}
+
 export function template(description) {
   return new Template(description);
 }