# Program or text editor to format existing HTML code

**URL:** https://boards.straightdope.com/t/program-or-text-editor-to-format-existing-html-code/526925
**Category:** Factual Questions
**Created:** [January 29, 2010, 7:14pm UTC](https://boards.straightdope.com/t/program-or-text-editor-to-format-existing-html-code/526925 "2010-01-29T19:14:28Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Roland\_Orzabal](https://avatars.discourse-cdn.com/v4/letter/r/c2a13f/32.png) [@Roland\_Orzabal](https://boards.straightdope.com/u/Roland_Orzabal)
#### Post date: [January 29, 2010, 7:14pm UTC](https://boards.straightdope.com/t/program-or-text-editor-to-format-existing-html-code/526925/1 "2010-01-29T19:14:28Z")

</div>

I need to modify a chunk of HTML code that was exported from another program. This code was never intended to be read by human eyes, so while it is technically error-free (tags properly ordered and closed, etc.), the formatting leaves much to desired. One line in particular is 16,548 characters long without a line break. You can see where this would be annoying to work with.

I’m looking for a program that will format this code to be more easily readable. It can either modify the file directly, or allow me to paste the contents into the program for formatting. Proper indenting would be wonderful, but anything that adds line breaks between tags at reasonable intervals would suit my purposes just fine. I’m hoping someone has had this same problem and has written an application specifically to solve it…this is just the sort of thing I’m usually good at googling up freeware for, but for whatever reason this one eludes me.

I presume I could do something like this with emacs, vi or the like, but I never learned either (yeah, I know, I’ll turn in my coder card later) and I don’t have time right now to learn a complex editor. That said, if there’s a built-in function that does this that’s relatively easy to apply, I’m game.

If there’s nothing out there specifically for this purpose, I can write a macro to throw in a line break after every end tag, but I’m hoping for something a little more…_elegant_ than that. Anyone have any suggestions?

---

<div class="post-metadata">

### Author: ![code\_grey](https://avatars.discourse-cdn.com/v4/letter/c/f4b2a3/32.png) [@code\_grey](https://boards.straightdope.com/u/code_grey)
#### Post date: [January 29, 2010, 7:36pm UTC](https://boards.straightdope.com/t/program-or-text-editor-to-format-existing-html-code/526925/2 "2010-01-29T19:36:38Z")

</div>

if you want to do line wrap, Firefox’s View -\> Wrap long lines will already handle this for you, at least for viewing. Whether or not you can then copy-paste the nicely wrapped text I am not sure.

This thread [browser addons - Is it possible to view HTML source auto-formatted in Firefox - Super User](http://superuser.com/questions/45590/is-it-possible-to-view-html-source-auto-formatted-in-firefox) brings up a Firefox plugin that allegedly can prettyprint html and javascript. Further, if you google for “prettyprint html”, here, [Google](http://www.google.com/#hl=en&source=hp&q=prettyprint+html&aq=f&aqi=g-s1g-sx2&oq=&fp=435311d5ec9ae78f), you will see various suggestions, some of them allegedly online available as public service.

---

<div class="post-metadata">

### Author: ![friedo](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@friedo](https://boards.straightdope.com/u/friedo)
#### Post date: [January 29, 2010, 8:06pm UTC](https://boards.straightdope.com/t/program-or-text-editor-to-format-existing-html-code/526925/3 "2010-01-29T20:06:02Z")

</div>

Just use [HTML Tidy](http://tidy.sourceforge.net/).

It’ll work as a filter, so you can easily pipe it to your favorite editor, or whatever suits your fancy.

---

<div class="post-metadata">

### Author: ![Roland\_Orzabal](https://avatars.discourse-cdn.com/v4/letter/r/c2a13f/32.png) [@Roland\_Orzabal](https://boards.straightdope.com/u/Roland_Orzabal)
#### Post date: [January 30, 2010, 8:46am UTC](https://boards.straightdope.com/t/program-or-text-editor-to-format-existing-html-code/526925/4 "2010-01-30T08:46:37Z")

</div>

> [@friedo](#):
>
> Just use [HTML Tidy](http://tidy.sourceforge.net/).
> 
> It’ll work as a filter, so you can easily pipe it to your favorite editor, or whatever suits your fancy.

Sweet, that’s exactly what I need. Even better, a bit of googling turned up a [GUI](http://www.paehl.de/tidy/) for it, so you don’t have to mess with command line hibbity-hoo for every file (unless you’re o’ of them \*nix types who prefer it that way ;)).

Many thanks!

---

<div class="post-metadata">

### Author: ![njtt](https://avatars.discourse-cdn.com/v4/letter/n/ecd19e/32.png) [@njtt](https://boards.straightdope.com/u/njtt)
#### Post date: [January 30, 2010, 9:09am UTC](https://boards.straightdope.com/t/program-or-text-editor-to-format-existing-html-code/526925/5 "2010-01-30T09:09:01Z")

</div>

_Dreamweaver_ would do it. But not for free, of course.
