4

Can anyone recommend a JavaScript-based code reformatter for HTML, CSS and JS?

I'm making a web-based IDE and I'd like to be able to tidy up some code without having to refresh the page or wait for an ajax request.

Note: I need it to be able to accept and return a string, and not work directly with HTML elements. My IDE doesn't use a textarea.

JasonMArcher
  • 13,296
  • 21
  • 55
  • 51
mpen
  • 256,080
  • 255
  • 805
  • 1,172

2 Answers2

3

Here's a few

[EDIT]: also found this script, it's what the html beautifier is based on.

Ilia Choly
  • 17,390
  • 14
  • 87
  • 153
  • 1
    "html beautifier jquery plugin" Doesn't seem to work. Its returning an "unexpected token" error – UserDy Dec 09 '14 at 16:38
2

HTML tidy is by far the best solution. Classic binary has been ported to javascript: How to format/tidy/beautify in JavaScript

Community
  • 1
  • 1
rickdog
  • 718
  • 8
  • 10
  • Playing the [demo](http://lovasoa.github.io/tidy-html5/demo.html), I'm not sure how I feel about it. I think it takes a few too many liberties with your HTML. – mpen May 16 '15 at 23:25