问题
Is there a tidy-like tool or a tidy configuration, which works fine with Jinja2 templates? The default tidy has problems with Jinja code in attributes and Jinja-loops are formated in an unreadable way. My main requirement is to get the indentation level right. Everything else is nice to have, but not required.
回答1:
You probably want a standalone tool and your question is old, so you've probably already solved it, but just in case this could be helpful. Some editors can handle jinja indent. For example vim with https://github.com/Glench/Vim-Jinja2-Syntax plugin. The '=' command fixes indent. So 'gg=G' fixes indent on all lines. gg to go to the first character; = to fix indent; and G means to the end.
回答2:
While it is not a standalone tool like HTML Tidy, the atom-beautify package for the Atom text editor works fine for me. I use atom-beautify when developing Flask/Jinja2 applications.
来源:https://stackoverflow.com/questions/17124365/tidy-for-jinja2-templates