3

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?

Sorskoot
  • 10,190
  • 6
  • 55
  • 98

2 Answers2

6

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

Have a look also at Syntax highlighting code with Javascript

Community
  • 1
  • 1
migajek
  • 8,524
  • 15
  • 77
  • 116
  • I use google prettify for syntax coloring. As far as I know none of the syntax highlighting plugins does formatting on the code. – Sorskoot Jun 17 '10 at 14:13
  • @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 Jun 17 '10 at 14:26
  • 1
    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 Jun 17 '10 at 14:34
  • 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 Jun 17 '10 at 16:21
1

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.

ioquatix
  • 1,411
  • 17
  • 32