I have code written in any programming language. How can I "prettify" it (bold if, else etc.) to display on a website? Are there any good APIs to do that?
Asked
Active
Viewed 1,483 times
2
-
4Could you specify, are you coding in an IDE? If so, they already have options to do that. For example, in Eclipse, you can choose a color scheme and make certain types of key words (like conditions) bold, italicized, etc. – rcplusplus Feb 25 '12 at 00:57
-
Do you mean syntax highlighting in an editor, or for export as, say, HTML with the markup? – Kitsune Feb 25 '12 at 00:57
-
No, I will have a website where this code should be prettified. – good_evening Feb 25 '12 at 00:57
-
Do you at least have a hint what the language is? – Johan Kotlinski Feb 25 '12 at 01:05
-
This question about Google Prettify should help you: http://stackoverflow.com/questions/1667097/how-to-get-google-prettify-to-render-more-like-visual-studio – Renato Feb 25 '12 at 01:10
-
But what I mean is, will the user give you a hint what the language is? Language detection is another topic – Johan Kotlinski Feb 25 '12 at 01:17
-
Language detection could be pretty difficult. It would be better if the user specify it (like in [Notepad++](http://notepad-plus-plus.org/)). – Luiggi Mendoza Feb 25 '12 at 01:24
-
Yes, user would tell me what language it would be. – good_evening Feb 25 '12 at 01:37
4 Answers
5
There is Google's prettify which is widely used for such tasks (e.g. SO itself uses it for highlighting of code).
Google Code Prettify JavaScript library supports all C-like (Java, PHP, C#, etc), Bash-like, and XML-like languages without need to specify the language and has customizable styles via CSS.
Moreover, as i know, there is a lot of third-party styles for those languages that not supported officially.

Community
- 1
- 1

om-nom-nom
- 62,329
- 13
- 183
- 228
0
If you're talking about an auto-formatter, I've used PEAR's PHP Beautifer before.
Although you shouldn't really need a script to format your code for you...

hohner
- 11,498
- 8
- 49
- 84