Prettify
This is similar to the prettify.js in JavaScript Prettify.
All comments are adapted from the JavaScript Prettify.
Some functions for browser-side pretty printing of code contained in html.
For a fairly comprehensive set of languages see the README file that came with this source. At a minimum, the lexer should work on a number of languages including C and friends, Java, Python, Bash, SQL, HTML, XML, CSS, Javascript, and Makefiles. It works passably on Ruby, PHP and Awk and a subset of Perl, but, because of commenting conventions, doesn't work on Smalltalk, Lisp-like, or CAML-like languages without an explicit lang class.
Usage:
include this source file in an html page via
<script type="text/javascript" src="/path/to/prettify.js"></script>
define style rules. See the example page for examples.
mark the
<pre>
and<code>
tags in your source withclass=prettyprint.
You can also use the (html deprecated)<xmp>
tag, but the pretty printer needs to do more substantial DOM manipulations to support that, so some css styles may not be preserved.
That's it. I wanted to keep the API as simple as possible, so there's no need to specify which language the code is in, but if you wish, you can add another class to the <pre>
or <code>
element to specify the language, as in <pre class="prettyprint lang-java">
. Any class that starts with "lang-" followed by a file extension, specifies the file type. See the "lang-*.js" files in this directory for code that implements per-language file handlers.
Change log:
cbeust, 2006/08/22
Java annotations (start with "@") are now captured as literals ("lit")*
Constructors
Types
Functions
Get the parser for the extension specified.