2

I have been looking around for a HTML formatter to incorporate with a project I am doing. I need it to be written in Javascript since I want the formatting done on the client side.

The problem is, the few that I have tried don't work very well... For example:

http://www.davidpirek.com/blog/html-beautifier-jquery-plugin : Has a problem with one of the For loops (in the cleanAsync function). Chrome says "unexpected token ILLEGAL"

JS Beautifier on GitHub : When I have links in the HTML it will put a newline character after it. The problem is, I have a period directly after the link in some cases and it will add a space between the link text and the period in the sentence. I tried poking around to fix it but I could not.

Are there any others, or does anyone have recommendations to fix the above two?

EDIT:

This is for editing code, so I just need something to tab in the lines, etc. The code output will go in a textarea.

Andrew M
  • 4,208
  • 11
  • 42
  • 67
  • 1
    The problem with the first one looks like that stray single-quote character in the loop. Probably just a typo by that blog author. – Pointy Mar 06 '11 at 20:00
  • When I tried removing the single quote Chrome was complaining about an unexpected parenthesis character. :/ – Andrew M Mar 06 '11 at 20:02
  • Is google's [Prettify](http://code.google.com/p/google-code-prettify/) an option? (It's what's used on here) – Brad Christie Mar 06 '11 at 20:43
  • It looks like Prettify will output a DIV that is colored, but I need to take the formatted code and stick it in a textarea for editing... Maybe I can modify it? – Andrew M Mar 06 '11 at 21:19

2 Answers2

1

use https://github.com/beautify-web/js-beautify and pass your code to html_beautify() method.

GorvGoyl
  • 42,508
  • 29
  • 229
  • 225