Ok, my situation is a bit different than all the threads here about formatting HTML. Also, I’ve installed about every HTML formatting plugin out there with mixed results and none really solve my issue.
Also, configuring these plugins can be difficult since I’m not a programmer and some authors don’t provide enough information to customize their plugins.
For now the only plugin that formats my HTML somewhat Ok is HTMLTidy, the problem is that it uses too much space per tag. See my HTML example below.
I also tried what they mentioned in this thread and it only works to some extent as far as indentation goes, but not really for ‘true’ markup formatting.
All I want to do is turn this markup:
<ul>
<li>
item here
</li>
<li>
item here
</li>
<li>
item here
</li>
</ul>
Or this one:
<p>
Content...
</p>
Into this:
<ul>
<li>item here</li>
<li>item here</li>
<li>item here</li>
</ul>
And this:
<p>Content...</p>
Having the content of every tag in a separate line from the opening/closing tags is a waste of space for me.
Any idea how to accomplish this either by modifying something in TidyHTML or manually, or any other way for that matter?
Thanks in advance.
Note: This solution works only in ST2, because at this moment (7/31/14) HTMLTidy is not available for ST3.
I figured a temporary solution, not ideal by any means, but…
Go to:
Preferences -> Key Bindings - User. You will be editing the file Default (Windows).sublime-keypmap.Add these two instructions to that file (note that the instructions need to be inside the [ ] brackets):
Save the file.
Make sure you have HTMLTidy installed. Open HTMLTidy’s Settings file HtmlTidy.sublime-settings:
Preferences -> Package Settings -> HtmlTidy -> Settings - Default.Look for
"indent": true,(include double quotes and comma) and change it tofalse.Save the file.
Go back to your HTML file and select a section of the code you want to format in one line. Yes, it doesn’t work if you select the entire markup o_O. It will only leave what’s inside the
<body>tag, and it will delete everything else (<html>,<head>, etc).Press CTRL+ALT+T to execute TidyHTML. This will shrink your markup and make the tags in one line.
Finally press CTRL+SHIFT+R to execute the indentation.
Good luck.