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?

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

4 Comments

I use google prettify for syntax coloring. As far as I know none of the syntax highlighting plugins does formatting on the code.
@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.
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 ;)
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: stackoverflow.com/questions/2709184/…
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.