views:

114

answers:

0

In dealing with a bunch of crufty Django template files, I want to indent them.

The files contain:

  • HTML, the bulk of the file. Maybe a pre tag or two.
  • JavaScript, inside script tags.
  • CSS inside the style tags
  • Django template directives inside {% ... %} pairs.

Surely there is a tool to do this. Most of the tools do silly things when facing unexpected characters. Which one works?

To clarify, what properly indents this code?

{% extends 'layout.html' %}
{% if admin %}
<style type="text/css">
body {
  color: purple;
  background-color: #d8da3d }
</style>
<p><b>ADMIN SCREEN</b></p>
{% endif %}
<script>
set_active_tab("Welcome");
if (first_time()) { turn_on_highlights(); }
</script>
<table><tr><td>a</td></tr><tr><td>b</td></tr></table>

I've tried various tools, including the Universal Indent GUI, without success.