npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

es2-code-prettify

v0.4.0

Published

Google Code Prettify for ES2

Downloads

22

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.

See an example.

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 classes 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

Flowchart of Google Code Prettify

Edit in draw.io

SimpleLexerRegistry

Edit in draw.io

License

ES2 Code Prettify is licensed under Apache License 2.0

(C) 2022-2023 itozyun(outcloud.blogspot.com)