forked from pest-parser/book
-
Notifications
You must be signed in to change notification settings - Fork 0
/
highlight-pest.js
41 lines (33 loc) · 1.35 KB
/
highlight-pest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Syntax highlighting for pest PEGs.
// mdBook exposes a minified version of highlight.js, so the language
// definition objects below have abbreviated property names:
// "b" => begin
// "c" => contains
// "cN" => className
// "e" => end
hljs.registerLanguage("pest", function(hljs) {
// Basic syntax.
var comment = {cN: "comment", b: "//", e: /$/};
var ident = {cN: "title", b: /[_a-zA-Z][_a-z0-9A-Z]*/};
var special = {b: /COMMENT|WHITESPACE/, cN: "keyword"};
// Escape sequences within a string or character literal.
var escape = {b: /\\./};
// Per highlight.js style, only built-in rules should be highlighted inside
// a definition.
var rule = {
b: /[@_$!]?\{/, e: "}",
k: {built_in: "ANY SOI EOI PUSH POP PEEK " +
"ASCII_ALPHANUMERIC ASCII_DIGIT ASCII_HEX_DIGIT " +
"ASCII_NONZERO_DIGIT NEWLINE"},
c: [comment,
{cN: "string", b: '"', e: '"', c: [escape]},
{cN: "string", b: "'", e: "'", c: [escape]}]
};
return {
c: [special, rule, ident, comment]
};
});
// This file is inserted after the default highlight.js invocation, which tags
// unknown-language blocks with CSS classes but doesn't highlight them.
Array.from(document.querySelectorAll("code.language-pest"))
.forEach(hljs.highlightBlock);