Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Indent, pretty-print code including Django template tags, HTML, CSS, and JavaScript [closed]

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.

like image 290
Charles Merriam Avatar asked Sep 02 '10 00:09

Charles Merriam


People also ask

Can you use Django with HTML and CSS?

Yes you will definitely need to know HTML and CSS. Django will take care of the 'back-end' which is basically the programming logic (user sign ins, database connection, page routing) where as HTML and CSS render the information to the user.

What are template tags in Django?

The template tags are a way of telling Django that here comes something else than plain HTML. The template tags allows us to to do some programming on the server before sending HTML to the client.

What does the built in Django template tag Lorem do?

lorem. Displays random “lorem ipsum” Latin text. This is useful for providing sample data in templates. A number (or variable) containing the number of paragraphs or words to generate (default is 1).


1 Answers

Try http://prettydiff.com/?m=beautify

See if that gets what you want. If you specifically need to address HTML tags that do not have a closing pair, such as <br>, then add the &html attribute to the address above. It should do everything you need as per the stated requirements.

like image 104
austincheney Avatar answered Oct 02 '22 23:10

austincheney