views:

40

answers:

2

Does anyone know if there's a jQuery plugin to format code, XML or HTML?

I'm showing the user some code on an html page. I use google prettify for coloring the syntax, but would like some indentation and linebreaks too. any suggestions?

+3  A: 

Here http://www.webdesignbooth.com/9-useful-javascript-syntax-highlighting-scripts/ the "beautyOfCode" is mentioned as jquery plugin.

Have a look also at http://stackoverflow.com/questions/160694/syntax-highlighting-code-with-javascript

migajek
I use google prettify for syntax coloring. As far as I know none of the syntax highlighting plugins does formatting on the code.
Sorskoot
@Sorskoot: Normally, source code is already formatted in a way. Can't you format it beforehand? Your code should be formatted in a proper way anyway.
Felix Kling
At a certain point a user has copy-pasted some code in a textbox. This is stored in the database. The user has pasted tabs or spaces, \n \r etc... I would like to reformat the code so that all code is displayed using the same format. I can build it myself, but if there's a library/plugin already is saves me some time ;)
Sorskoot
I don't know of any which does it in JavaScript, and I don't think there's any that handles really many languages. However have a look at PHP solutions: http://stackoverflow.com/questions/2709184/php-beautifiers-libraries-for-formatting-code
migajek
A: 

I made jQuery.Syntax : http://www.oriontransfer.co.nz/software/jquery-syntax

It integrates very well with jQuery, especially if you are doing dynamic formatting. Have a look at this example : http://www.syntax-highlighting.com/

I'm probably biased but I'd say its pretty good and easy to use.

Mr Samuel