Skip to content

Commit ccf6a75

Browse files
authored
feat: add highlight.js (#303)
used for syntax highlighting of annotated code examples theme by @rockerBOO
1 parent 5be1e32 commit ccf6a75

File tree

9 files changed

+697
-0
lines changed

9 files changed

+697
-0
lines changed

highlight/LICENSE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2006, Ivan Sagalaev.
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
* Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

highlight/highlight.min.js

Lines changed: 479 additions & 0 deletions
Large diffs are not rendered by default.

highlight/languages/bash.min.js

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

highlight/languages/c.min.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*! `c` grammar compiled for Highlight.js 11.6.0 */
2+
(()=>{var e=(()=>{"use strict";return e=>{const n=e.regex,t=e.COMMENT("//","$",{
3+
contains:[{begin:/\\\n/}]
4+
}),s="[a-zA-Z_]\\w*::",a="(decltype\\(auto\\)|"+n.optional(s)+"[a-zA-Z_]\\w*"+n.optional("<[^<>]+>")+")",r={
5+
className:"type",variants:[{begin:"\\b[a-z\\d_]*_t\\b"},{
6+
match:/\batomic_[a-z]{3,6}\b/}]},i={className:"string",variants:[{
7+
begin:'(u8?|U|L)?"',end:'"',illegal:"\\n",contains:[e.BACKSLASH_ESCAPE]},{
8+
begin:"(u8?|U|L)?'(\\\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4,8}|[0-7]{3}|\\S)|.)",
9+
end:"'",illegal:"."},e.END_SAME_AS_BEGIN({
10+
begin:/(?:u8?|U|L)?R"([^()\\ ]{0,16})\(/,end:/\)([^()\\ ]{0,16})"/})]},l={
11+
className:"number",variants:[{begin:"\\b(0b[01']+)"},{
12+
begin:"(-?)\\b([\\d']+(\\.[\\d']*)?|\\.[\\d']+)((ll|LL|l|L)(u|U)?|(u|U)(ll|LL|l|L)?|f|F|b|B)"
13+
},{
14+
begin:"(-?)(\\b0[xX][a-fA-F0-9']+|(\\b[\\d']+(\\.[\\d']*)?|\\.[\\d']+)([eE][-+]?[\\d']+)?)"
15+
}],relevance:0},o={className:"meta",begin:/#\s*[a-z]+\b/,end:/$/,keywords:{
16+
keyword:"if else elif endif define undef warning error line pragma _Pragma ifdef ifndef include"
17+
},contains:[{begin:/\\\n/,relevance:0},e.inherit(i,{className:"string"}),{
18+
className:"string",begin:/<.*?>/},t,e.C_BLOCK_COMMENT_MODE]},c={
19+
className:"title",begin:n.optional(s)+e.IDENT_RE,relevance:0
20+
},d=n.optional(s)+e.IDENT_RE+"\\s*\\(",u={
21+
keyword:["asm","auto","break","case","continue","default","do","else","enum","extern","for","fortran","goto","if","inline","register","restrict","return","sizeof","struct","switch","typedef","union","volatile","while","_Alignas","_Alignof","_Atomic","_Generic","_Noreturn","_Static_assert","_Thread_local","alignas","alignof","noreturn","static_assert","thread_local","_Pragma"],
22+
type:["float","double","signed","unsigned","int","short","long","char","void","_Bool","_Complex","_Imaginary","_Decimal32","_Decimal64","_Decimal128","const","static","complex","bool","imaginary"],
23+
literal:"true false NULL",
24+
built_in:"std string wstring cin cout cerr clog stdin stdout stderr stringstream istringstream ostringstream auto_ptr deque list queue stack vector map set pair bitset multiset multimap unordered_set unordered_map unordered_multiset unordered_multimap priority_queue make_pair array shared_ptr abort terminate abs acos asin atan2 atan calloc ceil cosh cos exit exp fabs floor fmod fprintf fputs free frexp fscanf future isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit tolower toupper labs ldexp log10 log malloc realloc memchr memcmp memcpy memset modf pow printf putchar puts scanf sinh sin snprintf sprintf sqrt sscanf strcat strchr strcmp strcpy strcspn strlen strncat strncmp strncpy strpbrk strrchr strspn strstr tanh tan vfprintf vprintf vsprintf endl initializer_list unique_ptr"
25+
},g=[o,r,t,e.C_BLOCK_COMMENT_MODE,l,i],m={variants:[{begin:/=/,end:/;/},{
26+
begin:/\(/,end:/\)/},{beginKeywords:"new throw return else",end:/;/}],
27+
keywords:u,contains:g.concat([{begin:/\(/,end:/\)/,keywords:u,
28+
contains:g.concat(["self"]),relevance:0}]),relevance:0},p={
29+
begin:"("+a+"[\\*&\\s]+)+"+d,returnBegin:!0,end:/[{;=]/,excludeEnd:!0,
30+
keywords:u,illegal:/[^\w\s\*&:<>.]/,contains:[{begin:"decltype\\(auto\\)",
31+
keywords:u,relevance:0},{begin:d,returnBegin:!0,contains:[e.inherit(c,{
32+
className:"title.function"})],relevance:0},{relevance:0,match:/,/},{
33+
className:"params",begin:/\(/,end:/\)/,keywords:u,relevance:0,
34+
contains:[t,e.C_BLOCK_COMMENT_MODE,i,l,r,{begin:/\(/,end:/\)/,keywords:u,
35+
relevance:0,contains:["self",t,e.C_BLOCK_COMMENT_MODE,i,l,r]}]
36+
},r,t,e.C_BLOCK_COMMENT_MODE,o]};return{name:"C",aliases:["h"],keywords:u,
37+
disableAutodetect:!0,illegal:"</",contains:[].concat(m,p,g,[o,{
38+
begin:e.IDENT_RE+"::",keywords:u},{className:"class",
39+
beginKeywords:"enum class struct union",end:/[{;:<>=]/,contains:[{
40+
beginKeywords:"final class struct"},e.TITLE_MODE]}]),exports:{preprocessor:o,
41+
strings:i,keywords:u}}}})();hljs.registerLanguage("c",e)})();

highlight/languages/lua.min.js

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

highlight/languages/python.min.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*! `python` grammar compiled for Highlight.js 11.6.0 */
2+
(()=>{var e=(()=>{"use strict";return e=>{
3+
const n=e.regex,a=/[\p{XID_Start}_]\p{XID_Continue}*/u,i=["and","as","assert","async","await","break","case","class","continue","def","del","elif","else","except","finally","for","from","global","if","import","in","is","lambda","match","nonlocal|10","not","or","pass","raise","return","try","while","with","yield"],s={
4+
$pattern:/[A-Za-z]\w+|__\w+__/,keyword:i,
5+
built_in:["__import__","abs","all","any","ascii","bin","bool","breakpoint","bytearray","bytes","callable","chr","classmethod","compile","complex","delattr","dict","dir","divmod","enumerate","eval","exec","filter","float","format","frozenset","getattr","globals","hasattr","hash","help","hex","id","input","int","isinstance","issubclass","iter","len","list","locals","map","max","memoryview","min","next","object","oct","open","ord","pow","print","property","range","repr","reversed","round","set","setattr","slice","sorted","staticmethod","str","sum","super","tuple","type","vars","zip"],
6+
literal:["__debug__","Ellipsis","False","None","NotImplemented","True"],
7+
type:["Any","Callable","Coroutine","Dict","List","Literal","Generic","Optional","Sequence","Set","Tuple","Type","Union"]
8+
},t={className:"meta",begin:/^(>>>|\.\.\.) /},r={className:"subst",begin:/\{/,
9+
end:/\}/,keywords:s,illegal:/#/},l={begin:/\{\{/,relevance:0},b={
10+
className:"string",contains:[e.BACKSLASH_ESCAPE],variants:[{
11+
begin:/([uU]|[bB]|[rR]|[bB][rR]|[rR][bB])?'''/,end:/'''/,
12+
contains:[e.BACKSLASH_ESCAPE,t],relevance:10},{
13+
begin:/([uU]|[bB]|[rR]|[bB][rR]|[rR][bB])?"""/,end:/"""/,
14+
contains:[e.BACKSLASH_ESCAPE,t],relevance:10},{
15+
begin:/([fF][rR]|[rR][fF]|[fF])'''/,end:/'''/,
16+
contains:[e.BACKSLASH_ESCAPE,t,l,r]},{begin:/([fF][rR]|[rR][fF]|[fF])"""/,
17+
end:/"""/,contains:[e.BACKSLASH_ESCAPE,t,l,r]},{begin:/([uU]|[rR])'/,end:/'/,
18+
relevance:10},{begin:/([uU]|[rR])"/,end:/"/,relevance:10},{
19+
begin:/([bB]|[bB][rR]|[rR][bB])'/,end:/'/},{begin:/([bB]|[bB][rR]|[rR][bB])"/,
20+
end:/"/},{begin:/([fF][rR]|[rR][fF]|[fF])'/,end:/'/,
21+
contains:[e.BACKSLASH_ESCAPE,l,r]},{begin:/([fF][rR]|[rR][fF]|[fF])"/,end:/"/,
22+
contains:[e.BACKSLASH_ESCAPE,l,r]},e.APOS_STRING_MODE,e.QUOTE_STRING_MODE]
23+
},o="[0-9](_?[0-9])*",c=`(\\b(${o}))?\\.(${o})|\\b(${o})\\.`,d="\\b|"+i.join("|"),g={
24+
className:"number",relevance:0,variants:[{
25+
begin:`(\\b(${o})|(${c}))[eE][+-]?(${o})[jJ]?(?=${d})`},{begin:`(${c})[jJ]?`},{
26+
begin:`\\b([1-9](_?[0-9])*|0+(_?0)*)[lLjJ]?(?=${d})`},{
27+
begin:`\\b0[bB](_?[01])+[lL]?(?=${d})`},{begin:`\\b0[oO](_?[0-7])+[lL]?(?=${d})`
28+
},{begin:`\\b0[xX](_?[0-9a-fA-F])+[lL]?(?=${d})`},{begin:`\\b(${o})[jJ](?=${d})`
29+
}]},p={className:"comment",begin:n.lookahead(/# type:/),end:/$/,keywords:s,
30+
contains:[{begin:/# type:/},{begin:/#/,end:/\b\B/,endsWithParent:!0}]},m={
31+
className:"params",variants:[{className:"",begin:/\(\s*\)/,skip:!0},{begin:/\(/,
32+
end:/\)/,excludeBegin:!0,excludeEnd:!0,keywords:s,
33+
contains:["self",t,g,b,e.HASH_COMMENT_MODE]}]};return r.contains=[b,g,t],{
34+
name:"Python",aliases:["py","gyp","ipython"],unicodeRegex:!0,keywords:s,
35+
illegal:/(<\/|->|\?)|=>/,contains:[t,g,{begin:/\bself\b/},{beginKeywords:"if",
36+
relevance:0},b,p,e.HASH_COMMENT_MODE,{match:[/\bdef/,/\s+/,a],scope:{
37+
1:"keyword",3:"title.function"},contains:[m]},{variants:[{
38+
match:[/\bclass/,/\s+/,a,/\s*/,/\(\s*/,a,/\s*\)/]},{match:[/\bclass/,/\s+/,a]}],
39+
scope:{1:"keyword",3:"title.class",6:"title.class.inherited"}},{
40+
className:"meta",begin:/^[\t ]*@/,end:/(?=#)|$/,contains:[g,m,b]}]}}})()
41+
;hljs.registerLanguage("python",e)})();

highlight/languages/ruby.min.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*! `ruby` grammar compiled for Highlight.js 11.6.0 */
2+
(()=>{var e=(()=>{"use strict";return e=>{
3+
const n=e.regex,a="([a-zA-Z_]\\w*[!?=]?|[-+~]@|<<|>>|=~|===?|<=>|[<>]=?|\\*\\*|[-/+%^&*~`|]|\\[\\]=?)",s=n.either(/\b([A-Z]+[a-z0-9]+)+/,/\b([A-Z]+[a-z0-9]+)+[A-Z]+/),i=n.concat(s,/(::\w+)*/),r={
4+
"variable.constant":["__FILE__","__LINE__"],
5+
"variable.language":["self","super"],
6+
keyword:["alias","and","attr_accessor","attr_reader","attr_writer","begin","BEGIN","break","case","class","defined","do","else","elsif","end","END","ensure","for","if","in","include","module","next","not","or","redo","require","rescue","retry","return","then","undef","unless","until","when","while","yield"],
7+
built_in:["proc","lambda"],literal:["true","false","nil"]},c={
8+
className:"doctag",begin:"@[A-Za-z]+"},t={begin:"#<",end:">"
9+
},b=[e.COMMENT("#","$",{contains:[c]}),e.COMMENT("^=begin","^=end",{
10+
contains:[c],relevance:10}),e.COMMENT("^__END__",e.MATCH_NOTHING_RE)],l={
11+
className:"subst",begin:/#\{/,end:/\}/,keywords:r},d={className:"string",
12+
contains:[e.BACKSLASH_ESCAPE,l],variants:[{begin:/'/,end:/'/},{begin:/"/,end:/"/
13+
},{begin:/`/,end:/`/},{begin:/%[qQwWx]?\(/,end:/\)/},{begin:/%[qQwWx]?\[/,
14+
end:/\]/},{begin:/%[qQwWx]?\{/,end:/\}/},{begin:/%[qQwWx]?</,end:/>/},{
15+
begin:/%[qQwWx]?\//,end:/\//},{begin:/%[qQwWx]?%/,end:/%/},{begin:/%[qQwWx]?-/,
16+
end:/-/},{begin:/%[qQwWx]?\|/,end:/\|/},{begin:/\B\?(\\\d{1,3})/},{
17+
begin:/\B\?(\\x[A-Fa-f0-9]{1,2})/},{begin:/\B\?(\\u\{?[A-Fa-f0-9]{1,6}\}?)/},{
18+
begin:/\B\?(\\M-\\C-|\\M-\\c|\\c\\M-|\\M-|\\C-\\M-)[\x20-\x7e]/},{
19+
begin:/\B\?\\(c|C-)[\x20-\x7e]/},{begin:/\B\?\\?\S/},{
20+
begin:n.concat(/<<[-~]?'?/,n.lookahead(/(\w+)(?=\W)[^\n]*\n(?:[^\n]*\n)*?\s*\1\b/)),
21+
contains:[e.END_SAME_AS_BEGIN({begin:/(\w+)/,end:/(\w+)/,
22+
contains:[e.BACKSLASH_ESCAPE,l]})]}]},g="[0-9](_?[0-9])*",o={className:"number",
23+
relevance:0,variants:[{
24+
begin:`\\b([1-9](_?[0-9])*|0)(\\.(${g}))?([eE][+-]?(${g})|r)?i?\\b`},{
25+
begin:"\\b0[dD][0-9](_?[0-9])*r?i?\\b"},{begin:"\\b0[bB][0-1](_?[0-1])*r?i?\\b"
26+
},{begin:"\\b0[oO][0-7](_?[0-7])*r?i?\\b"},{
27+
begin:"\\b0[xX][0-9a-fA-F](_?[0-9a-fA-F])*r?i?\\b"},{
28+
begin:"\\b0(_?[0-7])+r?i?\\b"}]},_={variants:[{match:/\(\)/},{
29+
className:"params",begin:/\(/,end:/(?=\))/,excludeBegin:!0,endsParent:!0,
30+
keywords:r}]},u=[d,{variants:[{match:[/class\s+/,i,/\s+<\s+/,i]},{
31+
match:[/class\s+/,i]}],scope:{2:"title.class",4:"title.class.inherited"},
32+
keywords:r},{relevance:0,match:[i,/\.new[ (]/],scope:{1:"title.class"}},{
33+
relevance:0,match:/\b[A-Z][A-Z_0-9]+\b/,className:"variable.constant"},{
34+
match:[/def/,/\s+/,a],scope:{1:"keyword",3:"title.function"},contains:[_]},{
35+
begin:e.IDENT_RE+"::"},{className:"symbol",
36+
begin:e.UNDERSCORE_IDENT_RE+"(!|\\?)?:",relevance:0},{className:"symbol",
37+
begin:":(?!\\s)",contains:[d,{begin:a}],relevance:0},o,{className:"variable",
38+
begin:"(\\$\\W)|((\\$|@@?)(\\w+))(?=[^@$?])(?![A-Za-z])(?![@$?'])"},{
39+
className:"params",begin:/\|/,end:/\|/,excludeBegin:!0,excludeEnd:!0,
40+
relevance:0,keywords:r},{begin:"("+e.RE_STARTERS_RE+"|unless)\\s*",
41+
keywords:"unless",contains:[{className:"regexp",contains:[e.BACKSLASH_ESCAPE,l],
42+
illegal:/\n/,variants:[{begin:"/",end:"/[a-z]*"},{begin:/%r\{/,end:/\}[a-z]*/},{
43+
begin:"%r\\(",end:"\\)[a-z]*"},{begin:"%r!",end:"![a-z]*"},{begin:"%r\\[",
44+
end:"\\][a-z]*"}]}].concat(t,b),relevance:0}].concat(t,b)
45+
;l.contains=u,_.contains=u;const w=[{begin:/^\s*=>/,starts:{end:"$",contains:u}
46+
},{className:"meta.prompt",
47+
begin:"^([>?]>|[\\w#]+\\(\\w+\\):\\d+:\\d+[>*]|(\\w+-)?\\d+\\.\\d+\\.\\d+(p\\d+)?[^\\d][^>]+>)(?=[ ])",
48+
starts:{end:"$",keywords:r,contains:u}}];return b.unshift(t),{name:"Ruby",
49+
aliases:["rb","gemspec","podspec","thor","irb"],keywords:r,illegal:/\/\*/,
50+
contains:[e.SHEBANG({binary:"ruby"})].concat(w).concat(b).concat(u)}}})()
51+
;hljs.registerLanguage("ruby",e)})();

0 commit comments

Comments
 (0)