Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime Text - Is there a way to automatically split tags onto new line?

I used a table generator to to convert a large Excel file into HTML, but much of the code runs across the same line, as shown below:

<tr><td>&nbsp;</td><td>&nbsp;</td><td>25%</td><td>25%</td><td>40%</td><td>10%</td></tr>
 <tr><td>IV</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;    </td></tr>

Is there a way for Sublime text to automatically break the tags onto individual lines for ease in adding all of the class styling I need to add?

Looking for the following:

 <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>5%</td>
    <td>0%</td>
    <td>95%</td>
    <td>&nbsp;</td>
 </tr>
 <tr>
    <td>II</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
 </tr> 
like image 731
thefreeline Avatar asked Oct 23 '13 02:10

thefreeline


2 Answers

The idea is first insert new line character after each tag, then re-indenting of code.

First Find all > characters, then replace it with >\n (Regular expression), then go to Edit, Line->Reindent. This way you can indent your code!

like image 179
Fatima Zohra Avatar answered Oct 12 '22 09:10

Fatima Zohra


If you have the Tag package installed you can simply select from the menu:

Edit -> Tag -> Auto-format Tags on Document
like image 37
skube Avatar answered Oct 12 '22 08:10

skube