googlearchive /code-prettify
An embeddable script that makes source-code snippets in HTML prettier.
★ 5,748⑂ 879👁 3⑃ 106● 509▤ 13
+1
日增长
5,748
stars
879
forks
3
watchers
106
prs
509
issues
13
releases
README
Status: Archived
!status: inactive
This repository has been archived and is no longer maintained.
---
JavaScript code prettifier
Announcement: Action required rawgit.com is going away.
An embeddable script that makes source-code snippets in HTML prettier.
Works on HTML pages.
Works even if code contains embedded links, line numbers, etc.
Simple API: include some JS & CSS and add an onload handler.
Lightweights: small download and does not block page from loading while
running.
Customizable styles via CSS. See the [themes gallery][1].
Supports all C-like, Bash-like, and XML-like languages. No need to specify
the language.
Extensible language handlers for other languages. You can specify the
language.
Widely used with good cross-browser support. Powers https://code.google.com/
and http://stackoverflow.com/
[See an example][2].
Setup
Include the script tag below in your document:
HTML
See Getting Started to configure that URL with
options you need.
Look at the [skin gallery][1] and pick styles that suit you.
Usage
Put code snippets in ... or
... and it will automatically be
pretty-printed.
HTML
class Voila {
public:
// Voila
static const string VOILA = "Voila";
// will not interfere with embedded tags.
}
FAQ
For which languages does it work?
The comments in prettify.js are authoritative but the lexer should work on a
number of languages including C and friends, Java, Python, Bash, SQL, HTML,
XML, CSS, JavaScript, Makefile, and Rust.
It works passably on Ruby, PHP, VB, and Awk and a decent subset of Perl and
Ruby, but because of commenting conventions, doesn't work on Smalltalk, OCaml,
etc. without a language extension.
Other languages are supported via extensions:
Apollo;
Basic;
Clojure;
CSS;
Dart;
Erlang;
Go;
Haskell;
Lasso;
Lisp, Scheme;
LLVM;
Logtalk;
Lua;
MATLAB;
MLs: F, Ocaml,SML;
Mumps;
Nemerle;
Pascal;
Protocol buffers;
R, S;
RD;
Rust;
Scala;
SQL;
Swift;
TCL;
LaTeX;
Visual Basic;
VHDL;
Wiki;
XQ;
YAML
If you'd like to add an extension for your favorite language, please look at
src/lang-lisp.js and submit a pull request.
How do I specify the language of my code?
You don't need to specify the language since PR.prettyPrint() will guess.
You can specify a language by specifying the language extension along with the
prettyprint class:
HTML
The lang- class specifies the language file extensions.
File extensions supported by default include:
"bsh", "c", "cc", "cpp", "cs", "csh", "cyc", "cv", "htm", "html", "java",
"js", "m", "mxml", "perl", "pl", "pm", "py", "rb", "sh", "xhtml", "xml",
"xsl".
You may also use the [HTML 5][3] convention of embedding a element
inside the and using language-java style classes:
HTML
...
It doesn't work on "obfuscated code sample"?
Yes. Prettifying obfuscated code is like putting lipstick on a pig —
i.e. outside the scope of this tool.
Which browsers does it work with?
It's been tested with IE 6, Firefox 1.5 & 2, and SafariTop issues
#127Newlines are not preserved in IE6,7,8 in code blocks (even with white-space:pre)0 comments · 2015-04-22#70C#/Java Syntax issue0 comments · 2015-04-22#334How to use Go language support with self serving2 comments · 2015-04-22#156When users copy code, line numbers are included with the copied text.4 comments · 2015-04-22#413Lazy render for performance11 comments · 2015-12-26#62Highlighting for unified diff5 comments · 2015-04-22#142HTML detection not as expected or detected inconsistently1 comments · 2015-04-22#498Consistently document and tag releases6 comments · 2017-07-24
Latest release
2013-03-04 2013-03-04 2016-12-17| File | Summary | Uploaded | Size | | --- | --- | --- | --- | | prettify-small-4-Mar-2013.tar.bz2 | Minimized JS and CSS sources | Mar 4, 2013 | 32.09KB | | prettify-4-Mar-2013.tar.bz2 | Bundle of source files, tests, and documentation | Mar 4, 2013 | 4.71MB |