title: Indent, pretty-print code including Django template tags, HTML, CSS, and JavaScript
body: <p>In dealing with a bunch of crufty Django template files, I want to indent them.</p>
  
  <p>The files contain:</p>
  
  <ul>
  <li>HTML, the bulk of the file.  Maybe a <em>pre</em> tag or two.</li>
  <li>JavaScript, inside <em>script</em> tags.</li>
  <li>CSS inside the <em>style</em> tags</li>
  <li>Django template directives inside <em>{% ... %}</em> pairs.</li>
  </ul>
  
  <p>Surely there is a tool to do this.  Most of the tools do silly things when facing unexpected characters.   Which one works?</p>
  
  <p>To clarify, what properly indents this code?</p>
  
  <pre><code>{% extends 'layout.html' %}
  {% if admin %}
  &lt;style type="text/css"&gt;
  body {
    color: purple;
    background-color: #d8da3d }
  &lt;/style&gt;
  &lt;p&gt;&lt;b&gt;ADMIN SCREEN&lt;/b&gt;&lt;/p&gt;
  {% endif %}
  &lt;script&gt;
  set_active_tab("Welcome");
  if (first_time()) { turn_on_highlights(); }
  &lt;/script&gt;
  &lt;table&gt;&lt;tr&gt;&lt;td&gt;a&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;b&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
  </code></pre>
  
  <p>I've tried various tools, including the Universal Indent GUI, without success.  </p>