Correct reformat of HTML

This forum is user-to-user based and not regularly monitored by IDM.
Please see the note at the top of this page on how to contact IDM.

Correct reformat of HTML

Postby Lofi » Sun Mar 05, 2006 8:35 am

is there a way to correctly reformat html in ultraedit, especially block-tags? i haven't found one so far.

i've currently found a way to reformat the html source of a webpage with the firefox extension "view reformatted source". it successfully indents the html correctly, but unfortunately when i copy/paste the code from there to ultraedit i get a flat list, so the firefox extension doesn't work correctly for me.

the flat list looks like this:

Code: Select all
<html>
<head>
</head>
<body>
<table>
<tr>
<td>
<input name="">
<input name="">
<input name="">
</td>
</tr>
</table>
<div>
<br>some text
<br>
</div>
</body>
</html>


reindenting that code in ultraedit delivers:

Code: Select all
<html>
   <head>
   </head>
   <body>
      <table>
         <tr>
            <td>
               <input name="">
                  <input name="">
                     <input name="">
                     </td>
                  </tr>
               </table>
               <div>
                  <br>some text
                  <br>
               </div>
            </body>
         </html>


which is absolutely not requested. it indents every tag, e. g. incorrectly the <input> tag several times.

so the solution might be to indent only block tags. is there a way to achieve this in ultraedit?

or even better: is there a way to reformat the html correctly so that there will be a line break plus the correct indention after every html tag?

what i want is this:

Code: Select all
<html>
   <head>
   </head>
   <body>
      <table>
         <tr>
            <td>
               <input name="">
               <input name="">
               <input name="">
            </td>
         </tr>
      </table>
      <div>
         <br>some text
         <br>
      </div>
   </body>
</html>


thanks.

ps: please no 3rd party product suggestions like htmltidy ;)
User avatar
Lofi
Newbie
 
Posts: 2
Joined: Sun Mar 05, 2006 12:00 am

Re: Correct reformat of HTML

Postby Lofi » Sun Mar 05, 2006 11:11 am

Add-on to my last reply: found a bug with the wordfile.txt & html combination in version 11.20

e.g. META:

/Indent Strings = "<HTML" "<HEAD" "<META"
/Unindent Strings = "</HTML" "</HEAD" "</META"

would deliver the following wrong indention:

Code: Select all
<html>
   <head>
      <meta>
   </meta>
   <meta content="dummy" name="dummy">
</meta>

<script type="text/javascript" src="/dummy.js">
</script>
</head>
<body>
</body>
</html>

the meta doesn't get outdented correctly

and the default wordfile.txt:

/L9"JavaScript" JSCRIPT_LANG
...
/Indent Strings = "{" "else"
/Unindent Strings = "}"

leads to this:

Code: Select all
<script type="text/javascript">

   function dummy() {
      if ()
         open();
         else
            close();
         

      }

   </script>

hence the else should be removed/corrected in my opinion as it never gets outdented
User avatar
Lofi
Newbie
 
Posts: 2
Joined: Sun Mar 05, 2006 12:00 am

Re: Correct reformat of HTML

Postby Grover » Wed Oct 04, 2006 12:11 pm

I haven't tested extensively, but I believe you're looking for this command (which is present in v. 12.10b, at least):

Format: Reindent Selection

It could probably be replaced with something a lot fancier, but all I've needed so far is enough formatting to let me find my way through my predecessors' many nested tables.
User avatar
Grover
Newbie
 
Posts: 3
Joined: Mon Sep 18, 2006 11:00 pm

Re: Correct reformat of HTML

Postby bdkbdk » Thu Oct 05, 2006 12:24 pm

Hi

I took the posted code, pasted it into Ultraedit, saved it as a html file, marked the whole file (Ctrl+A), chose Format->ReIndent Selection, and voila, the code was indented just as you requested.
User avatar
bdkbdk
Newbie
 
Posts: 2
Joined: Wed Oct 04, 2006 11:00 pm

Re: Correct reformat of HTML

Postby paulkdeuter » Sun Aug 02, 2009 1:52 pm

Hi,
I am still having trouble with html formatting. Neither reformat paragraph or reindent selection seem to do what I want. My request is the same as the original post: simple html formatting where tags at the same nest level are started on separate lines and have the same indentation.
Suppose you started with totally unformatted html: <div id="n11"><div id="n21"><div id="n31"></div></div><div id="n22"></div></div>
What are all the steps necessary to have UE format it as:

Code: Select all
<div id="n11">
    <div id="n21">
        <div id="n31">
        </div>
    </div>
    <div id="n22">
    </div>
</div>

Btw: I just noticed a new command called "XML Convert to CRLFs" which does what I want perfectly! But this command is grayed out unless the file has the extension ".xml" ... boo!

How about enabling that command for .htm, .html, .xhtml files and also for new windows where the text is not saved at all yet. I am asking for this because xml/html formatting is often the first step of troubleshooting problematic html that was cut/pasted from another source in a new window. I am not interested in saving this text at all, but rather just formatting it so that I can read it.

-Paul Deuter
paulkdeuter
Newbie
 
Posts: 1
Joined: Sun Aug 02, 2009 1:10 pm

Re: Correct reformat of HTML

Postby Mofi » Mon Aug 03, 2009 12:03 am

Command "XML Convert to CRLFs" is mainly for XML, but works also for XHTML. You don't need to change the file extension to use it for HTML. You just have to select the XML syntax highlighting language at View - View As (Highlighting File Type) for your file.

However, for HTML there is usually a better tool than "XML Convert to CRLFs", Format - HTML Validation - Run HTML Tidy. HTML Tidy is a tool to check a HTML file for errors and can also output a well formatted version of a HTML file. You just have to configure the HTML Tidy options to what you like. Read the HTML Tidy manual for details about the options.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4062
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to UltraEdit General Discussion