es2-code-prettify
v0.4.0
Published
Google Code Prettify for ES2
Downloads
19
Maintainers
Readme
Code Prettify for ES2
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.
Comparison
Usage
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>
How to build
Please see gulpfile.js or web-doc-base / gulpfile.js.
gulp all
gulp web
FAQ
For which languages does it work?
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
How do I specify the language of my code?
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>
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 5, Gecko 0.6, Opera 7.0. Look at the tests to see if it works in your browser.
How do I put line numbers in my code?
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>
How do I prevent a portion of markup from being marked as code?
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.
How can I customize the colors and styles of my code?
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.
How can I put line numbers on every line instead of just every fifth line?
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>
Charts
License
ES2 Code Prettify is licensed under Apache License 2.0
(C) 2022-2023 itozyun(outcloud.blogspot.com)