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
  • 14,195
  • 22
  • 56
  • 52
mpen
  • 272,448
  • 266
  • 850
  • 1,236

2 Answers2

3

Here's a few

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

Ilia Choly
  • 18,070
  • 14
  • 92
  • 160
  • 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
  • 748
  • 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