how to pretty print source code of common languages in browser html output with javascript?
Asked Answered
P

3

7

how to pretty print source code of common languages in browser html output with javascript?

I mean so that there is some indentation and code formatting. Currently i only got http://alexgorbatchev.com/SyntaxHighlighter/ for coloring the syntax. But i would also like some indentation and other formatting.

Example: user puts in some code. system formats and highlights code in the browser view. so-> is there a general code formatter for formatting code? best in javascript

I am grateful for any help.

Providential answered 27/2, 2011 at 13:17 Comment(3)
you are at the right place.. stack overflow does syntax highlighting.. why dnt u just flick that js code.. :DSmectic
Tools for syntax highlighting are much more common than tools for code formatting. It may be easier to run an existing tool on the server and get the formatted version via AJAX.Joggle
The AJAX idea is not bad. You know any good formatters?Providential
T
7

Probably SyntaxHighlighter is the most popular. But you have a choice, have a look at 16 Free Javascript Code Syntax Highlighters For Better Programming

If you mean real time syntax highlighter, you can also try JS-CodeEdit:

JS-CodeEdit is a JavaScript editor that converts your HTML textareas into a code editor with realtime syntax highlighting. If added into a form, the content can be submitted e.g. to be written to a file. A nice thing is that you can add as many editors as you want within a HTML page.

But it support a bit limited list of languages: JavaScript, PHP, Perl, HTML, CSS, XML, SQL (this list is increased with each release).

Telescopium answered 27/2, 2011 at 14:11 Comment(2)
All links are dead, except JS-CodeEdit, but which last updated in 2011.Crinkly
SyntaxHighlighter is here: github.com/syntaxhighlighter/syntaxhighlighter and 16 free highlighters can bee found here: egloos.zum.com/metalkin/v/5585544Bronwen
A
1

You might want to check out Giki : http://guyht.github.com/Giki/examples/wiki.html

Its a real time syntax highlighter, very easy to customise.

GitHub Repo: https://github.com/guyht/Giki

Andel answered 25/3, 2011 at 13:59 Comment(1)
Project isn't up anymore, do you have a fork/mirror?Depersonalize
P
1

Here is a open source command line program, with optional GUI, which can format and highlight approx. 100 programming languages, with configurable colour themes and output as HTML, XHTML, RTF, TeX, LaTeX, terminal escape sequences, SVG and BBCode format. See the complete feature list, examples, screenshots and screencast.

There is also a macOS quick view plugin available, too. This is not Javascript but you can do the stuff ex. via AJAX.

Providential answered 29/3, 2011 at 13:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.