Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prettify Jinja2 Template

I have a Jinja2 template that I'd like to use, but can't in conjunction with prettifying the code. This question has been asked before, but that hasn't had an answer in almost 2 years, so perhaps there's an answer out there now.

<select id="example-getting-started" name="test" multiple="multiple">
   {% for k in pizza_dict %}
      <option value="{{ k }}" {% if pizza_dict[k] %}selected{% endif %}>{{ k }}</option>
   {% endfor %}
</select>

BeautifulSoup and lxml will "prettify" this code to:

<select id="example-getting-started" multiple="multiple" name="test"> 
{% for k in pizza_dict %} 
    <option endif="" if="" pizza_dict="" value="{{ k }}"> {{ k }} </option> 
{% endfor %} </select>

which will destroy the code's function.

like image 407
Michael K Avatar asked Apr 17 '15 17:04

Michael K


1 Answers

Recently I was seeking for some tool for autoformatting and found the VSOT: https://pypi.org/project/vsot/

like image 165
Rodrigo Avatar answered Oct 01 '22 09:10

Rodrigo