JavaScript code prettifier based on Google Code Prettify.
Language files are fully compatible with Google Code Prettify.
- Works on HTML pages.
- Works even if code contains embedded links, line numbers, etc.
- Customizable styles via CSS. See the themes gallery.
Google Code Prettify | ES2 Code Prettify | |
---|---|---|
Lower limit of supported browsers | IE6, Gecko 1.8, Opera 8 | 🌸IE5, 🌸Gecko 0.6, 🌸Opera 7.0 |
Languages | Add dynamically except built-in | Select the language to be used on the site or page at build time |
Dynamic addition of theme | ✔ | ✖ |
File size | 🌸14.551 bytes | 50,042 bytes(+24KB: RegExp ponyfill), Build with "web,c,cs,java,bash,python,perl,ruby,coffee" .
|
Dependency | 🌸none | web-doc-base, what-browser-am-i, ES2 RegExpCompat |
Line Numbering | ✔ | ✔ (You can disable the function at build time.) |
Set by comment node | ✔ | ✔ (You can disable the feature at build time. Some browsers do not support comment nodes.) |
Execution by time division | Manual. Measure and schedule the elapsed time at the time to finish highlighting the code block. | Always. Elapsed time is measured and scheduled at each timing of regular expression instance creation, token creation, and decoration. |
Put code snippets in <pre class="prettyprint">...</pre>
or
<code class="prettyprint">...</code>
and it will automatically be
pretty-printed.
<pre class="prettyprint">class Voila {
public:
// Voila
static const string VOILA = "Voila";
// will not interfere with embedded <a href="#voila2">tags</a>.
}</pre>
Please see gulpfile.js or web-doc-base / gulpfile.js.
gulp all
gulp web
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.
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
You can specify a language by specifying the language extension along with the
prettyprint
class:
<pre class="prettyprint lang-html">
The lang-* class specifies the language file extensions.
</pre>
You may also use the HTML 5 convention of embedding a <code>
element
inside the <pre>
and using language-java
style classes:
<pre class="prettyprint"><code class="language-java">...</code></pre>
Yes. Prettifying obfuscated code is like putting lipstick on a pig — i.e. outside the scope of this tool.
It's been tested with IE 5, Gecko 0.6, Opera 7.0. Look at the tests to see if it works in your browser.
You can use the linenums
class to turn on line numbering. If your code
doesn't start at line number 1
, you can add a colon and a line number to the
end of that class as in linenums:52
. For example:
<pre class="prettyprint linenums:4"
>// This is line 4.
foo();
bar();
baz();
boo();
far();
faz();
</pre>
You can use the nocode
class to identify a span of markup that is not code:
<pre class="prettyprint">
int x = foo(); /* This is a comment <span class="nocode">This is not code</span>
Continuation of comment */
int y = bar();
</pre>
For a more complete example see the issue #22 testcase.
Prettify adds <span>
with class
es describing the kind of code. You can
create CSS styles to matches these classes.
See the theme gallery for examples.
Prettify puts lines into an HTML list element so that line numbers aren't
caught by copy/paste, and the line numbering is controlled by CSS in the
default stylesheet, prettify.css
.
The following should turn line numbering back on for the other lines:
<style>
li.L0, li.L1, li.L2, li.L3,
li.L5, li.L6, li.L7, li.L8 {
list-style-type: decimal !important;
}
</style>
ES2 Code Prettify is licensed under Apache License 2.0
(C) 2022-2023 itozyun(outcloud.blogspot.com)