From f6a103f52abc42eaeba29b7bbfcd9c622f043154 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 30 Apr 2024 17:24:55 -0300 Subject: html: html.smooth() --- src/util/html.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src') 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); } -- cgit 1.3.0-6-gf8a5