The examples in this page serve a dual purpose: They act as unit tests, making it easy to spot bugs, and at the same time demonstrate what Prism can do, on simple and on edge cases.
p { color: red; }
p { color: red; }
p { color: red; }
p { color: red; }
p { color: red; }
p { color: red; }
No language, should inherit .language-markup
<p>hi!</p>
No language, should inherit .language-markup
<p>hi!</p>
Should not be highlighted.
<p>hi!</p>
<p></p>
<p
>hello!
</p>
<p></p>
<p class=prism></p>
<p data-foo></p>
<p data-foo ></p>
<html:p foo:bar="baz" foo:weee></html:p>
<?xml version="1.0" encoding="utf-8"?>
<svg></svg>
<!DOCTYPE html>
<html></html>
<ns1:description><![CDATA[
CDATA is <not> magical.
]]></ns1:description>
<!-- I'm a comment -->
And i'm not
& ♥   Œ
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>I can haz embedded CSS and JS</title>
<style>
@media print {
p { color: red !important; }
}
</style>
</head>
<body>
<h1>I can haz embedded CSS and JS</h1>
<script>
if (true) {
console.log('foo');
}
</script>
</body>
</html>
<l </ul>
<p title="foo
bar
baz">
*{} * {} p {}
ul,
ol {}
p { color: red; }
p { color: red !important; }
@media screen and (min-width: 100px) {}
@main-color: red;
.foo {
background: @main-color;
}
/* Simple comment here */
content: 'foo';
content: url(foo.png);
var foo = "bar", baz = 5;
(1 + 2 * 3)/4 >= 3 && 4 < 5 || 6 > 7
if (true) {
while (true) {
doSomething();
}
}
var foo = /([^/])\/(\\?.|\[.+?])+?\/[gim]{0,3}/g;
var bar = /\/\*[\w\W]*?\*\//g;
// http://lea.verou.me
var comment = /\/\*[\w\W]*?\*\//g;
// http://lea.verou.me
/* http://lea.verou.me */
var foo = "foo", bar = "He \"said\" 'hi'!"
// "foo"
/* "foo" */
env.content + '</' + env.tag + '>'
var foo = "/" + "/";
var foo = "http://prismjs.com"; // Strings are strings and comments are comments ;)
// hey, /this doesn’t fail!/ :D
var foo = 5 / 6 / 7;
var foo = 1/2, bar = /a/g;
var foo = /a/, bar = 3/4;
abstract continue for new switch
assert default goto package synchronized
boolean do if private this
break double implements protected throw
byte else import public throws
case enum instanceof return transient
catch extends int short try
char final interface static void
class finally long strictfp volatile
const float native super while
// postfix
expr++ expr--
// unary
++expr --expr +expr -expr ~ !
// multiplicative
* / %
// additive
+ -
// shift
<< >> >>>
// relational
< > <= >= instanceof
// equality
== !=
// bitwise AND
&
// bitwise exclusive OR
^
// bitwise inclusive OR
|
// logical AND
&&
// logical OR
||
// ternary
? :
// assignment
= += -= *= /= %= &= ^= |= <<= >>= >>>=
package com.prismjs;
import java.io.*;
@SuppressWarnings("unchecked")
public class PrismJS {
public static Integer test = 0;
/**
* Javadoc style comment
*
* @param args
*/
public static void main(String[] args) {
// Let's create some variables
int numArgs = args.length;
Integer a = 0x1;
String test = "" + "Hello" + " \"World\"!";
double dvalue = 1.23;
int optest = 0;
optest += 321 - 45 * 1247 / 425 % 123;
/*
* Multiline comment
*/
for (int i = 0; i < numArgs; i++) {
// Simple line comment
System.out.println("Arg value= " + args[i]);
}
do {
System.out.println("Do while ok!");
} while (false);
}
}
As you can notice String keyword is not highlighted because it's not a Java language keyword (cf. Java Language Keywords). The main reason is that String is not a primitive type such as int but a class type like Integer.
foo = "bar"
(1 + 2 * 3)/4 >= 3 && 4 < 5 || 6 > 7
if true
while true
doSomething()
var foo = /([^/])\/(\\?.|\[.+?])+?\/[gim]{0,3}/g;
# This is a comment
# http://lea.verou.me
###
Block Comment
###
var foo = "foo", bar = "He \"said\" 'hi'!"
# "foo"
env.content + '</' + env.tag + '>'
var foo = "/" + "/";
foo = 5 / 6 / 7;
foo = 1/2, bar = /a/g;
foo = /a/, bar = 3/4;
_buttonClick: (a, b) ->
@hide()
code = {
css: "Cascading Style Sheets"
cs: "CoffeeScript"
}
class CoffeeScript extends Prism.Javascript
A simple HTTP GET request:
GET https://example.tld/v1/:serviceName/users.json?sort=:sortMethod HTTP/1.1
Here is an HTTP POST with a body:
POST https://example.tld/v1/:serviceName/users.json HTTP/1.1
Content-Type: application/json
{
"names": ["test1", "test2"],
"version": 1.0
}
JSON response body:
HTTP/1.1 200 OK
Content-Type: application/json
X-Response-Time: 6ms
{
"users": [
{
"name": "John",
"points": 24
},
{
"name": "Lea",
"points": 15
}
]
}
XML response body:
HTTP/1.1 200 OK
Content-Type: application/xml
X-Response-Time: 10ms
<root>
<status code="0">
Successful
</status>
</root>
a←1 2 3
1e6 2j3 3.14 'a' 'abc' ⍬
#!/usr/bin/env runapl
a←1 2 3 ⍝ this is a comment
a+b×c⍴⍳10
+/ f⍣2
{0=⍴⍴⍺:'hello' ⋄ ∇¨⍵}
There are certain edge cases where Prism will fail. There are always such cases in every regex-based syntax highlighter. However, Prism dares to be open and honest about them. If a failure is listed here, it doesn’t mean it will never be fixed. This is more of a “known bugs” list, just with a certain type of bug.
"foo /* bar */ baz"; "foo // bar";
foo = /"foo"/;