HTML Formatter in Javascript

4.1k views Asked by At

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.

2

There are 2 answers

0
GorvGoyl On

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