title: Prettify Jinja2 Template
body: <p>I have a Jinja2 <a href="https://stackoverflow.com/questions/29704737/jinja2-templating-boolean-variables-cleanly/29704917#29704917">template</a> that I'd like to use, but can't in conjunction with prettifying the code. <a href="https://stackoverflow.com/questions/17124365/tidy-for-jinja2-templates">This question</a> has been asked before, but that hasn't had an answer in almost 2 years, so perhaps there's an answer out there now.</p>
  
  <pre><code>&lt;select id="example-getting-started" name="test" multiple="multiple"&gt;
     {% for k in pizza_dict %}
        &lt;option value="{{ k }}" {% if pizza_dict[k] %}selected{% endif %}&gt;{{ k }}&lt;/option&gt;
     {% endfor %}
  &lt;/select&gt;
  </code></pre>
  
  <p>BeautifulSoup and lxml will "prettify" this code to:</p>
  
  <pre><code>&lt;select id="example-getting-started" multiple="multiple" name="test"&gt; 
  {% for k in pizza_dict %} 
      &lt;option endif="" if="" pizza_dict="" value="{{ k }}"&gt; {{ k }} &lt;/option&gt; 
  {% endfor %} &lt;/select&gt;
  </code></pre>
  
  <p>which will destroy the code's function.</p>