Skip to content

remove whitespace #390

Description

@fkv1

The Template Toolkit provides an easy syntax for removing leading and trailing whitespace:
[%- instead of [% removes all whitespace (including newlines) before the directive
-%] instead of %] removes all whitespace (including newlines) after the directive

The latter is barely ever needed, but the removal of leading whitespace is very important.

This feature is missing in Mako. You can only add a backslash at the end of the line to eat the newline. But that's insufficient in several respects:

  1. It's counter-intuitive. If you insert a block, you don't want to edit other lines to compensate for the effects of the inserted block. Same when you remove the block. There's a high probability you'll forget to remove the backslash in the preceding line.
  2. diffs and patches also become more confusing if the preceding line needs to be changed when you remove or insert a block.
  3. if you have:
<div>
    aaa\
    <%
        (some python code)
    %>
    bbb
</div>

or

<div>
    aaa
    <%
        (some python code)
    %>\
    bbb
</div>

you get:

<div>
    aaa
        bbb
</div>

(because only the newline is chomped, not the spaces)

but you want:

<div>
    aaa
    bbb
</div>

Of course you can remove the indentation of the Mako block, but at the cost of readability.

The Template Toolkit approach would be:

<div>
    aaa
    <%-
        (some python code)
    %>
    bbb
</div>

Can this be implemented?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions