-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit introduces the concept of Errorless Indenting™. From now on, there will be no more `syntax error on line X` messages. The template will be indented no matter what. The reason that errors aren't fatal anymore is that the improved parsing algorithm now gives correct output when Django template tags and HTML tags are mixed in seemingly paradoxal ways. In almost all cases DjHTML indents the template exactly how I would have done it manually. Which is really the goal of this program, after all. For the remaining cases, the new `{# fmt:off #}` tag disables formatting, similar to Black. Closes #17
- Loading branch information
Showing
8 changed files
with
196 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<!-- Common pattern in django templates --> | ||
{% if %} | ||
<a> | ||
{% else %} | ||
<a> | ||
{% endif %} | ||
. | ||
{% if %} | ||
</a> | ||
{% endif %} | ||
|
||
|
||
<!-- The literal example from issue #17 --> | ||
{% if some_condition %} | ||
<a href="{% url some_url"> | ||
{% elif some_other_condition %} | ||
<a href="{% url some_other_url"> | ||
{% endif %} | ||
[a bunch of details go here] | ||
{% if end_tag_needed %}</a>{% endif %} | ||
|
||
|
||
<!-- Deep nestings should be instantly dedented --> | ||
{% block %} | ||
<a> | ||
<a> | ||
<a> | ||
<a> | ||
<a> | ||
{% endblock %} | ||
{% for x in [1,2,3,4,5] %} | ||
</a> | ||
{% endfor %} | ||
|
||
|
||
<!-- The most complicated example I can think of --> | ||
<body> | ||
{% if %} | ||
<div> | ||
{% else %} | ||
<span>{% if %}<blink> | ||
{% block %} | ||
</blink> | ||
{% endblock %}{% endif %} | ||
{% endif %} | ||
. | ||
{% if %} | ||
</span> | ||
{% else %} | ||
</div> | ||
{% endif %} | ||
</body> | ||
|
||
|
||
<!-- Inside <script> tag --> | ||
<script> | ||
{% if jquery %} | ||
$(function() { | ||
{% else %} | ||
document.addEventListener("DOMContentLoaded", function(event) { | ||
{% endif %} | ||
console.log("Time to ditch jQuery!") | ||
}); | ||
</script> | ||
|
||
|
||
<!-- Manually disable formatting --> | ||
<body> | ||
{# fmt:off #} | ||
,-._|\ | ||
/ .\ | ||
\_,--._/ | ||
{# fmt:on #} | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<!-- Common pattern in django templates --> | ||
{% if %} | ||
<a> | ||
{% else %} | ||
<a> | ||
{% endif %} | ||
. | ||
{% if %} | ||
</a> | ||
{% endif %} | ||
|
||
|
||
<!-- The literal example from issue #17 --> | ||
{% if some_condition %} | ||
<a href="{% url some_url"> | ||
{% elif some_other_condition %} | ||
<a href="{% url some_other_url"> | ||
{% endif %} | ||
[a bunch of details go here] | ||
{% if end_tag_needed %}</a>{% endif %} | ||
|
||
|
||
<!-- Deep nestings should be instantly dedented --> | ||
{% block %} | ||
<a> | ||
<a> | ||
<a> | ||
<a> | ||
<a> | ||
{% endblock %} | ||
{% for x in [1,2,3,4,5] %} | ||
</a> | ||
{% endfor %} | ||
|
||
|
||
<!-- The most complicated example I can think of --> | ||
<body> | ||
{% if %} | ||
<div> | ||
{% else %} | ||
<span>{% if %}<blink> | ||
{% block %} | ||
</blink> | ||
{% endblock %}{% endif %} | ||
{% endif %} | ||
. | ||
{% if %} | ||
</span> | ||
{% else %} | ||
</div> | ||
{% endif %} | ||
</body> | ||
|
||
|
||
<!-- Inside <script> tag --> | ||
<script> | ||
{% if jquery %} | ||
$(function() { | ||
{% else %} | ||
document.addEventListener("DOMContentLoaded", function(event) { | ||
{% endif %} | ||
console.log("Time to ditch jQuery!") | ||
}); | ||
</script> | ||
|
||
|
||
<!-- Manually disable formatting --> | ||
<body> | ||
{# fmt:off #} | ||
,-._|\ | ||
/ .\ | ||
\_,--._/ | ||
{# fmt:on #} | ||
</body> |