How to: use Google Code Prettify
Setup Google Code Prettify on your Website
Syntax highlighting is one of the basic needs of websites that feature code. I’m using Google Code Prettify or Prettyprint to highlight code on this website.
Why I use Google Code Prettify
Here are some reasons why I prefer using Google prettify to highlight and decorate the code bits.
- Lightweightedness
- Flexibility
- Dependency-free
- Easy theming
Because it’s fast, efficiently-programmed and supports various code themes for syntax highlighting, it can be one step closer to speeding up your website.
GCP takes care of all the decorated code you see here. Rest of this article covers its installation and implementation step-by-step on our website.
Setting up Google Code Prettify
That’s it. We’re done with the installation.
Implemnation
Add .prettyprint
class to any code block and it gets highlighted automatically. Below is a working example of GCP.
<pre class"prettyprint"><style>
/* This is some CSS code */
.red { color: red; }
.green { color: green; }
.blue {color: blue; }
</style></pre>
Make sure to make your code HTML-friendly by parsing characters like <
, >
, &
and others.
The Code prettify is smart enough to detect the code type and then style it automatically. Here is the list of the languages and styles it supports and provides for code highlighting.
Currently, I’m using a modded GitHub-style theme created by jmblog. You may also create a color theme by yourself, but that I’ll cover some other day.
Load Comments...