latte icon indicating copy to clipboard operation
latte copied to clipboard

FR: macro to trim whitespaces around

Open milo opened this issue 1 year ago • 0 comments

Multiple whitespace characters in HTML text nodes are rendered as a single space. Would be useful to do not render it at all in some cases. For example in imaginary wiki page footer:

<footer>
    Version {$ver}
    created by {$author}
    {ifset $category}(in category {$category}{/}.
</footer>

If $category is not set, extrace space is rendered by browser before dot.

Version 1 created by Milo .

To solve that I use this formatting but it makes code and commits harder to read:

<footer>
    Version {$ver}
    created by {$author}{ifset $category}
    (in category {$category}{/}.
</footer>

Some macro like {trim} or unpaired version of {spaceless} would be usesul. Such macro would delete all whitespace-only text nodes around itself.

note: In case of trim, optional charlist could be provided, like {trim ":, \n"}.

An example above could look like:

<footer>
    Version {$ver}
    created by {$author} {trim}
    {ifset $category}
         (in category {$category}) {trim}
    {/}.
</footer>

milo avatar Nov 01 '24 18:11 milo