diff options
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 |
commit | f6a103f52abc42eaeba29b7bbfcd9c622f043154 (patch) | |
tree | ec6c3c7e7f368276894e54e2f157aea0a1b6e3f3 | |
parent | c8c9c465b241062570cc3955c01fb5d59d20d888 (diff) |
html: html.smooth()
-rw-r--r-- | src/util/html.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/util/html.js b/src/util/html.js index d1d509e2..0f190e25 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); } |