Statac

How a built page's source is laid out

How the HTML Statac writes keeps a template's lines and indents.

Statac lays out the HTML it writes as the template lays out its own lines. Take this part of a template:

<main>
    {{ page.content }}
</main>

Statac builds that as

<main>
    <p>The first paragraph.</p>
    <ul>
      <li>One</li>
      <li>Two</li>
    </ul>
</main>

Statac adds no indentation or blank lines of its own, and removes no blank lines.

  • A line with only a template tag on it, such as {% if %} or {% for %}, leaves nothing in the output.
  • A line that starts with a tag and has more on it, such as {% if page.summary %}<p>{{ page.summary }}</p>{% endif %}, keeps its indent and its line end. If the part between its tags writes nothing, Statac leaves the line out.
  • A line that ends with a tag and has more on it, such as <p>{{ page.title }}</p>{% if page.summary %}, keeps its line end, so the next line starts on a line of its own. If Statac doesn’t write the branch after it, the tag closing the branch on a line of its own ends the line instead. This holds inside <pre> and <script> too.
  • A loop whose end tag closes the last line of its body, such as <li>{{ item.title }}</li>{% endfor %} on the line after {% for item in items %}, writes each pass on lines of its own if that body is indented. If the body is at the left, or inside <pre>, <textarea>, <script> or <style>, Statac writes the passes one after another exactly as typed, so no line end comes between items meant to touch.
  • A value on a line of its own, such as {{ page.content }} or a snippet call: Statac indents each of its lines to match that line. If the value is empty, Statac leaves the line out.
  • A body written from somewhere else, that is a macro’s or a {% set %} block’s body written by its call or its name, such as {{ card() }}, or what a {% call %} or a {% filter %} writes, starts at the indent of the line where that call, name or tag stands alone, and its lines keep their indent relative to each other. So a body indented under its {% macro %} or {% filter %} tag loses that indent. If the call, name or tag is at the left, or shares its line, Statac writes the body exactly as typed.
  • Inside such a body, every rule here holds as it does on the page: a value alone on its line, such as {{ caller() }} or another macro’s call, lines up at that line’s indent; a loop’s or branch’s body indented only so the template reads well loses that indent; and Statac leaves out a line that comes to nothing. The line that writes the body decides where it lands, wherever the template defines the macro.
  • A block’s body indented only so the template reads well, such as a loop’s body under a {% for %} that stands level with the line before it: Statac writes it at the indent of the lines round it. If the indent belongs to the markup, such as a body one step inside the <ul> its {% for %} stands level with, or if Statac can’t tell which you meant, Statac writes the lines exactly as typed.
  • A block’s body that replaces another template’s, as with extends, keeps the indent its lines have relative to each other, and starts at the indent of the line where the {% block %}{% endblock %} tags stand together, or of the body it replaces if the tags stand on lines of their own. Inside a line, as in <title>{% block title %}{% endblock %}</title>, Statac writes it exactly as typed. {{ super() }} on a line of its own lines up at that line’s indent.
  • A recursive loop’s deeper levels: Statac indents each by as much as its {{ loop(...) }} is indented inside the {% for %} tag.
  • Lines inside <pre>, <textarea> and an attribute’s value: Statac leaves them unchanged.

A template that writes plain text or JSON keeps every line’s indent as typed.

Something unclear or wrong? Open an issue.