code-prettify: custom lang with multiple keyword classes
by Amro
HTML
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/prettify.js"></script>
<link rel="stylesheet" href="https://cdn.rawgit.com/google/code-prettify/master/loader/prettify.css">
<h2>Custom</h2>
<pre class="prettyprint lang-processing">
hello world! Bye.
</pre>
<h2>Java</h2>
<pre class="prettyprint lang-java">
class JavaExample {
public static void main(String args[]) {
System.out.println("Hello World!");
}
}
</pre>
CSS
/* if you dont style these custom classes, */
/* they will fallback to the regular kwd class */
.kwd1 { color: aqua; }
.kwd2 { color: teal; }
JavaScript
// define custom language handler
var PR_KEYWORD1 = 'kwd1 kwd';
var PR_KEYWORD2 = 'kwd2 kwd';
PR.registerLangHandler(
PR.createSimpleLexer(
[
],
[
[PR_KEYWORD1, /^(?:hi|hello)\b/i],
[PR_KEYWORD2, /^(?:bye|goodbye)\b/i]
]),
['processing']);
// apply syntax highlighting
PR.prettyPrint();