How to beautify part of code

  • Advertisement ( why? )
     

    patter, 13th Nov 2012 12:41 pm

    I have a snippit of code that I would like to have the html aligned. Tidy does that but it also adds in missing items like doctype and closing tables. Is there a way to just align the code without having anythng added?

    • HTML-Kit Support, 13th Nov 2012 1:15 pm

      On 11/13/2012 12:41 PM, patter wrote:

      I have a snippit of code that I would like to have the html aligned.
      Tidy does that but it also adds in missing items like doctype and
      closing tables. Is there a way to just align the code without having
      anythng added?

      Hi,

      For simple line indenting, I just select the lines (Shift key down and
      up/down arrows), and press Tab or Shift+Tab. And repeat that if there
      are a few more levels inside that block.

      You could also open a block of tags in a new document using "File > New

      New from clipboard" and click Tidy. Tidy, as you said, is going to
      add the missing tags so the relevant tags would have to be copied back.

      Chami

      • patter, 13th Nov 2012 4:54 pm

        Thanks, but neither of those will work. Well, the first one would work but the block of code is large (about 150 lines) and I was trying to find a way to doing it automatically, especially since this is not the only time I will need to do so. The block of code has a lot of openings of tables and rows but not closing ones. So to remove the code that Tidy adds would require saving the new file and doing a compare with the original to see what should be removed. Oh well, it was worth a try. Thanks for the quick response.

        By the way, I refreshed the screen without realizing the page hadn't redirected so there is a duplicate post of this question. It can be deleted if you like.

        • HTML-Kit Support, 13th Nov 2012 5:03 pm

          On 11/13/2012 4:54 PM, patter wrote:

          Thanks, but neither of those will work. Well, the first one would
          work but the block of code is large (about 150 lines) and I was
          trying to find a way to doing it automatically, especially since this
          is not the only time I will need to do so. The block of code has a
          lot of openings of tables and rows but not closing ones. So to remove
          the code that Tidy adds would require saving the new file and doing a
          compare with the original to see what should be removed. Oh well, it
          was worth a try. Thanks for the quick response.

          Having tags that aren't closed is problematic specially when it comes to
          beautifying code. It might be useful in the long run to balance out
          those tags by closing them, not only for the purposes of beautifying and
          validating, but also to make it easier to read and find matching tags.

          By the way, I refreshed the screen without realizing the page hadn't
          redirected so there is a duplicate post of this question. It can be
          deleted if you like.

          No biggie :) I had already replied to it pointing to this thread so
          we'll just leave it there.

          Chami

          • patter, 14th Nov 2012 7:43 am

            It's php code and there are includes so they all get closed, just not in this piece of code. Tidy, apparently, assumes the code is supposed to be a properly formmated html page and that won't work in this case.

        • bill, 14th Nov 2012 6:19 am

          On 11/13/2012 5:54 PM, patter wrote:

          Thanks, but neither of those will work. Well, the first one would work but the block of code is large (about 150 lines) and I was trying to find a way to doing it automatically, especially since this is not the only time I will need to do so. The block of code has a lot of openings of tables and rows but not closing ones. So to remove the code that Tidy adds would require saving the new file and doing a compare with the original to see what should be removed. Oh well, it was worth a try. Thanks for the quick response.

          By the way, I refreshed the screen without realizing the page hadn't redirected so there is a duplicate post of this question. It can be deleted if you like.

          marking a large block of code is not difficult:
          left-click at the beginning of the block
          navigate to the end of the block
          shift left-click will select all the text between the first click
          and the 2nd.

          No help for the repetitive part though.

          bill

          • patter, 14th Nov 2012 7:47 am

            Selecting the code isn't the problem. The problem is that the resulting code has extra code in it. Try creating a new file with these lines[code]<tr>
            <td>[/code]I would like tidy to return sometihng like [code]<tr>
            <td>[/code]but it does that and then adds another 10 or so lines of code.