I've got some poorly-formatted HTML code that I'd like to reformat. Is there a command that will automatically reformat HTML code in Sublime Text 2 so it looks better and is easier to read?
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
- implementing html5 drag and drop photos with knock
-
Why does the box-shadow property not apply to a
I think this is what you're looking for:
https://github.com/victorporof/Sublime-HTMLPrettify
There are half a dozen or so ways to format HTML in Sublime. I've tested each of the most popular plugins (see the writeup I did on my blog for full details), but here's a quick overview of some of the most popular options:
Reindent command
Pros:
Cons:
<script>
blocksTag
Pros:
Cons:
<script>
blocks correctlyHTMLTidy
Pros:
Cons:
HTMLBeautify
Pros:
Cons:
HTML-CSS-JS Prettify
Pros:
Cons:
Which is best?
HTML-CSS-JS Prettify is the winner in my book. Lots of great features, not much to complain about.
I created a Package called HTMLBeautify that does a decent job of reformatting HTML. I based it off of a Perl script I found back in 1997—I updated it to work with all the new fangled modern tags. :)
Check it out and let me know what you think!
https://github.com/rareyman/HTMLBeautify
You don't need any plugins to do this. Just select all lines (Ctrl A) and then from the menu select Edit → Line → Reindent. This will work if your file is saved with an extension that contains HTML like
.html
or.php
.If you do this often, you may find this key mapping useful:
If your file is not saved (e.g. you just pasted in a snippet to a new window), you can manually set the language for indentation by selecting the menu View → Syntax →
language of choice
before selecting the reindent option.Simply go to
Edit -> Tag -> Auto-format tags on document
There is a nice open source CodeFormatter plugin, which(along reindenting) can beautify dirty code even all of it is in single line.