Question:
How to arrange HTML code structure?
hush_pumpkin
2010-01-31 03:52:46 UTC
I'm a web designer and I have to redesign a website. It's giving me headaches lately. Everything on the code is in one line only (rather than arranged in a column for future coders to easily understand). I hand code html using notepad ++ and everything on his html's body is in one row or line. Is there any software that can automatically arrange and clean the html's structure?
Five answers:
?
2010-02-03 16:00:27 UTC
Hands down the best product for that is Tidy.



What's better is that it is free.



There are online versions available, such as: http://infohound.net/tidy/



Or download an executable (and/or source code) from: http://tidy.sourceforge.net/
anonymous
2016-02-27 07:00:56 UTC
Anybody that says if you want to learn programming you should start from HTML should be shot in the head. HTML is radically different from programming or scripting. HTML is codes to describe data. Program/Scripts is codes to describe process. Contrary to what oracle says, HTML coding is also coding. Though it is very different to coding program/scripts. This is not to say that you shouldn't learn HTML though. HTML is easier than programming, and learning it allows you to get used to working in text-based environments (don't use WYSIWYG editors). All decent application developer knows at least some HTML. Also, HTML has a little fully-fledged scripting language called Javascript.
random guy
2010-01-31 03:59:46 UTC
what i did when that happened with a website from i was given to manage was turn on word wrap in normal notepad and it does a pretty good job of course the coding was still hard as heck to read and i cleaned it up manually but word wrap in notepad was a big help for when i had to get it done fast.
amazzed.co.uk
2010-01-31 04:24:41 UTC
you should try aptana studio it is free, load your html into aptana and then right click and select format.



it will arrange all the html in lines with indents for ul/li etc



hope it helps
Namibnat
2010-01-31 05:40:08 UTC
You hardly need software to do that. Any simple scripting language can do it. In Python it would be only a few lines. You can do this in a complex way, but even if you just replace every ">" with ">\n" then you will be fine:



In Python (which you may have on your system anyway...if you have linux or mac - just go to the command line and type 'python') you could do this:

>>>r = open('/path/to/yr/file.htm', 'r')

>>>toParse = r.read()

>>>r.close()

>>>import re

>>>wasParsed = re.sub(">", ">\n", toParse)

>>>w = open('path/to/yr/file.htm', 'w')

>>>for i in wasParsed: w.write(i)

>>>w.close()



That's it. It could be done better, and you don't even really need regular expression. But doing this is so simple and you would save yourself installing something. If you have Python and want to try it, you could write to a second file just to test, before committing it finally. If you have any trouble, there are so many good Python forums, such as the one on Daniweb.com



I just show Python code so that you can do it even if you don't know any scripting language, but you can see that it's a really operation, and can be done a whole lot better if you do have a scripting language.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...