quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.

Home Page:https://quarkus.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Qute: Remove empty lines

gbourant opened this issue · comments

Description

I have the following Qute tag htmx.html

{! core attributes !}
{#if hx-boost.notNull??}hx-boost="{hx-boost}"{/if}
{#if hx-get.notNull??}hx-get="{hx-get}"{/if}
{#if hx-post.notNull??}hx-post="{hx-post}"{/if}
{#if hx-on.notNull??}hx-on="{hx-on}"{/if}
{#if hx-push-url.notNull??}hx-push-url="{hx-push-url}"{/if}
{#if hx-select.notNull??}hx-select="{hx-select}"{/if}
{#if hx-select-oob.notNull??}hx-select-oob="{hx-select-oob}"{/if}
{#if hx-swap.notNull??}hx-swap="{hx-swap}"{/if}
{#if hx-swap-oob.notNull??}hx-swap-oob="{hx-swap-oob}"{/if}
{#if hx-target.notNull??}hx-target="{hx-target}"{/if}
{#if hx-trigger.notNull??}hx-trigger="{hx-trigger}"{/if}
{#if hx-vals.notNull??}hx-vals="{hx-vals}"{/if}
{! additional attributes !}
{#if hx-confirm.notNull??}hx-confirm="{hx-confirm}"{/if}
{#if hx-delete.notNull??}hx-delete="{hx-delete}"{/if}
{#if hx-disable.notNull??}hx-disable="{hx-disable}"{/if}
{#if hx-disinherit.notNull??}hx-disinherit="{hx-disinherit}"{/if}
{#if hx-encoding.notNull??}hx-encoding="{hx-encoding}"{/if}
{#if hx-ext.notNull??}hx-ext="{hx-ext}"{/if}
{#if hx-headers.notNull??}hx-headers="{hx-headers}"{/if}
{#if hx-history.notNull??}hx-history="{hx-history}"{/if}
{#if hx-history-elt.notNull??}hx-history-elt="{hx-history-elt}"{/if}
{#if hx-include.notNull??}hx-include="{hx-include}"{/if}
{#if hx-indicator.notNull??}hx-indicator="{hx-indicator}"{/if}
{#if hx-params.notNull??}hx-params="{hx-params}"{/if}
{#if hx-patch.notNull??}hx-patch="{hx-patch}"{/if}
{#if hx-preserve.notNull??}hx-preserve="{hx-preserve}"{/if}
{#if hx-prompt.notNull??}hx-prompt="{hx-prompt}"{/if}
{#if hx-put.notNull??}hx-put="{hx-put}"{/if}
{#if hx-replace-url.notNull??}hx-replace-url="{hx-replace-url}"{/if}
{#if hx-request.notNull??}hx-request="{hx-request}"{/if}
{#if hx-sse.notNull??}hx-sse="{hx-sse}"{/if}
{#if hx-sync.notNull??}hx-sync="{hx-sync}"{/if}
{#if hx-validate.notNull??}hx-validate="{hx-validate}"{/if}
{#if hx-vars.notNull??}hx-vars="{hx-vars}"{/if}
{#if hx-ws.notNull??}hx-ws="{hx-ws}"{/if}

Then i have another tag email.html.

<input type="email" {#htmx _unisolated/}>

Which i use

{#email hx-get="/url" /}

The problem with this approach is that when the {#email} tag is rendered it has many empty lines caused by {#htmx} which makes it hard to read/debug/test.

result

<input type="email" 


// many empty lines
hx-get="/url"
// many empty lines


>

Maybe we can add something like the _unisolated, let's call it _standalone which will remove the empty lines and can be used {#if _standalone hx-boost.notNull??}hx-boost="{hx-boost}"{/if}. So if the line evaluates to an empty line and it has the _standalone remove the empty line.

Or be able to configure Qute to remove all empty lines or don't generate them at the first place?

Implementation ideas

No response

/cc @mkouba (qute)

Hm, this is weird. Standalone lines should be removed by default. See Removing Standalone Lines From the Template. I will try to reproduce the problem with your code.

I was able to reproduce the problem locally. {#if hx-boost.notNull??}hx-boost="{hx-boost}"{/if} is not considered a standalone line that can be removed because the content is not blank, i.e. it contains an output expression and some text literals. The line is not empty from the parser POV.

One of the workarounds is to use a content filter that would remove all line separators from a specific template. But it's not very nice.

I will try to think of a better solution.

I can't think of a better solution.

When I mentioned the content filters I meant something like this:

void configureEngine(@Observes EngineBuilder builder) {
   builder.addParserHook(new ParserHook() {
      @Override
      public void beforeParsing(ParserHelper helper) {
         if (helper.getTemplateId().startsWith("htmx")) {
            helper.addContentFilter(c -> c.replace("\r", "").replace("\n", ""));       
         }
      }
   });
}

Feel free to reopen this issue if the workaround does not work or is too cumbersome.