rtts / djhtml

Django/Jinja template indenter
GNU General Public License v3.0
582 stars 32 forks source link

Skip certain lines/Retain Indentation #29

Closed rickdonato closed 3 years ago

rickdonato commented 3 years ago

Is there a way to skip the formatting of certain lines. or retain there current indentation. For example:

❯ cat   example2.j2
{% if router_bgp %}
{%    for neighbor in bgp_neighbors %}
router bgp {{ router_asn }}
   neighbor {{ neighbor['ip'] }} description {{ neighbor['description'] }}
   neighbor {{ neighbor['ip'] }} peer-group {{ neighbor['peer_group'] }}
{%    endfor %}
{% endif %}
❯ djhtml  example2.j2
{% if router_bgp %}
    {%    for neighbor in bgp_neighbors %}
        router bgp {{ router_asn }}
        neighbor {{ neighbor['ip'] }} description {{ neighbor['description'] }}
        neighbor {{ neighbor['ip'] }} peer-group {{ neighbor['peer_group'] }}
    {%    endfor %}
{% endif %}

Is there a way to prevent any indentation for the router and neighbour lines for example or keep their current indentation, and append?

JaapJoris commented 3 years ago

Hi there, and thanks for contributing! This feature was added in 11186526676fffe520d96c9e498f3d3f168c3234 but I forgot to document it. My apologies. You can exclude specific lines from being processed with the {# fmt:off #} and {# fmt:on #} operators:

<div class="
    {# fmt:off #}
      ,-._|\
     /     .\
     \_,--._/
    {# fmt:on #}
/>

I have added this cute little bunny to the README as well!