Použití formátovače

Formátovač djLint vezme neupravené HTML šablony a sjednotí jejich formátování, aby byly přehledné a snadno čitelné!

Než změny použijete, prohlédněte si výstup s --check.

Chcete-li zjistit, co se při formátování může změnit, spusťte:

djlint . --check

Chcete-li kód naformátovat a soubory aktualizovat, spusťte:

djlint . --reformat --single-attribute-per-line

# a co takhle naformátovat i skripty a styly?
djlint . --reformat --single-attribute-per-line --format-css --format-js

Poznámka

JSON a JavaScript zapsané v atributu zůstávají beze změny, pokud není zapnuté --format-attribute-js-json. HTML uvnitř atributu zůstává vždy beze změny.

Poznámka

djLint není parser HTML ani validátor syntaxe.

Ukázka

Před

Tady je kus HTML, který zoufale potřebuje péči:

{% load admin_list %}
{% load i18n %}
<p class="paginator">
{% if pagination_required %}
{% for i in page_range %}
{% paginator_number cl i %}
{% endfor %}
{% endif %}
{{ cl.result_count }}
{% if cl.result_count == 1 %}
{{ cl.opts.verbose_name }}
{% else %}
{{ cl.opts.verbose_name_plural }}
{% endif %}
{% if show_all_url %}
<a href="{{ show_all_url }}" class="showall">{% translate 'Show all' %}</a>
{% endif %}
{% if cl.formset and cl.result_count %}
<input type="submit" name="_save" class="default" value="{% translate 'Save' %}">
{% endif %}
</p>

Po

Teď to vypadá o něco lépe… dá se to přečíst :)

{% load admin_list %}
{% load i18n %}
<p class="paginator">
    {% if pagination_required %}
        {% for i in page_range %}
            {% paginator_number cl i %}
        {% endfor %}
    {% endif %}
    {{ cl.result_count }}
    {% if cl.result_count == 1 %}
        {{ cl.opts.verbose_name }}
    {% else %}
        {{ cl.opts.verbose_name_plural }}
    {% endif %}
    {% if show_all_url %}
        <a href="{{ show_all_url }}" class="showall">{% translate "Show all" %}</a>
    {% endif %}
    {% if cl.formset and cl.result_count %}
        <input type="submit"
               name="_save"
               class="default"
               value="{% translate 'Save' %}">
    {% endif %}
</p>

Po s single_attribute_per_line

Dáváte přednost atributům ve stylu Prettier? Zapněte možnost single_attribute_per_line:

{% load admin_list %}
{% load i18n %}
<p class="paginator">
    {% if pagination_required %}
        {% for i in page_range %}
            {% paginator_number cl i %}
        {% endfor %}
    {% endif %}
    {{ cl.result_count }}
    {% if cl.result_count == 1 %}
        {{ cl.opts.verbose_name }}
    {% else %}
        {{ cl.opts.verbose_name_plural }}
    {% endif %}
    {% if show_all_url %}
        <a href="{{ show_all_url }}" class="showall">{% translate "Show all" %}</a>
    {% endif %}
    {% if cl.formset and cl.result_count %}
        <input
            type="submit"
            name="_save"
            class="default"
            value="{% translate 'Save' %}"
        >
    {% endif %}
</p>