Skip to content

Commit 1568083

Browse files
committed
R: enable syntax highlighting
1 parent e9c854c commit 1568083

File tree

2 files changed

+61
-23
lines changed

2 files changed

+61
-23
lines changed

assets/javascripts/vendor/prism.js

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* PrismJS 1.23.0
2-
https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+bash+c+cpp+coffeescript+crystal+d+dart+diff+django+elixir+erlang+go+groovy+java+json+julia+kotlin+latex+lua+markup-templating+matlab+nginx+nim+ocaml+perl+php+python+jsx+ruby+rust+scss+shell-session+sql+typescript+yaml */
2+
https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+bash+c+cpp+coffeescript+crystal+d+dart+diff+django+elixir+erlang+go+groovy+java+json+julia+kotlin+latex+lua+markup-templating+matlab+nginx+nim+ocaml+perl+php+python+r+jsx+ruby+rust+scss+shell-session+sql+typescript+yaml */
33
/// <reference lib="WebWorker"/>
44

55
var _self = (typeof window !== 'undefined')
@@ -1231,7 +1231,7 @@ Prism.languages.markup = {
12311231
greedy: true,
12321232
inside: {
12331233
'internal-subset': {
1234-
pattern: /(\[)[\s\S]+(?=\]>$)/,
1234+
pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/,
12351235
lookbehind: true,
12361236
greedy: true,
12371237
inside: null // see below
@@ -1369,7 +1369,7 @@ Object.defineProperty(Prism.languages.markup.tag, 'addAttribute', {
13691369
pattern: /=[\s\S]+/,
13701370
inside: {
13711371
'value': {
1372-
pattern: /(=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,
1372+
pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,
13731373
lookbehind: true,
13741374
alias: [lang, 'language-' + lang],
13751375
inside: Prism.languages[lang]
@@ -1399,7 +1399,7 @@ Prism.languages.rss = Prism.languages.xml;
13991399

14001400
(function (Prism) {
14011401

1402-
var string = /("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;
1402+
var string = /(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;
14031403

14041404
Prism.languages.css = {
14051405
'comment': /\/\*[\s\S]*?\*\//,
@@ -1432,14 +1432,23 @@ Prism.languages.rss = Prism.languages.xml;
14321432
}
14331433
}
14341434
},
1435-
'selector': RegExp('[^{}\\s](?:[^{};"\'\\s]|\\s+(?![\\s{])|' + string.source + ')*(?=\\s*\\{)'),
1435+
'selector': {
1436+
pattern: RegExp('(^|[{}\\s])[^{}\\s](?:[^{};"\'\\s]|\\s+(?![\\s{])|' + string.source + ')*(?=\\s*\\{)'),
1437+
lookbehind: true
1438+
},
14361439
'string': {
14371440
pattern: string,
14381441
greedy: true
14391442
},
1440-
'property': /(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,
1443+
'property': {
1444+
pattern: /(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,
1445+
lookbehind: true
1446+
},
14411447
'important': /!important\b/i,
1442-
'function': /[-a-z0-9]+(?=\()/i,
1448+
'function': {
1449+
pattern: /(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,
1450+
lookbehind: true
1451+
},
14431452
'punctuation': /[(){};:,]/
14441453
};
14451454

@@ -1479,7 +1488,7 @@ Prism.languages.clike = {
14791488
},
14801489
'keyword': /\b(?:if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
14811490
'boolean': /\b(?:true|false)\b/,
1482-
'function': /\w+(?=\()/,
1491+
'function': /\b\w+(?=\()/,
14831492
'number': /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
14841493
'operator': /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
14851494
'punctuation': /[{}[\];(),.:]/
@@ -1523,8 +1532,8 @@ Prism.languages.insertBefore('javascript', 'keyword', {
15231532
alias: 'language-regex',
15241533
inside: Prism.languages.regex
15251534
},
1526-
'regex-flags': /[a-z]+$/,
1527-
'regex-delimiter': /^\/|\/$/
1535+
'regex-delimiter': /^\/|\/$/,
1536+
'regex-flags': /^[a-z]+$/,
15281537
}
15291538
},
15301539
// This must be declared before keyword because we use "function" inside the look-forward
@@ -1539,7 +1548,8 @@ Prism.languages.insertBefore('javascript', 'keyword', {
15391548
inside: Prism.languages.javascript
15401549
},
15411550
{
1542-
pattern: /(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,
1551+
pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,
1552+
lookbehind: true,
15431553
inside: Prism.languages.javascript
15441554
},
15451555
{
@@ -1837,7 +1847,7 @@ Prism.languages.c = Prism.languages.extend('clike', {
18371847
lookbehind: true
18381848
},
18391849
'keyword': /\b(?:__attribute__|_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|asm|typeof|inline|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while)\b/,
1840-
'function': /[a-z_]\w*(?=\s*\()/i,
1850+
'function': /\b[a-z_]\w*(?=\s*\()/i,
18411851
'number': /(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,
18421852
'operator': />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/
18431853
});
@@ -1846,7 +1856,7 @@ Prism.languages.insertBefore('c', 'string', {
18461856
'macro': {
18471857
// allow for multiline macro definitions
18481858
// spaces after the # character compile fine with gcc
1849-
pattern: /(^\s*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im,
1859+
pattern: /(^[\t ]*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im,
18501860
lookbehind: true,
18511861
greedy: true,
18521862
alias: 'property',
@@ -1913,7 +1923,7 @@ delete Prism.languages.c['boolean'];
19131923
/\b[A-Z_]\w*(?=\s*::\s*~\w+\s*\()/i,
19141924
// This also intends to capture the class name of method implementations but here the class has template
19151925
// parameters, so it can't be a namespace (until C++ adds generic namespaces).
1916-
/\w+(?=\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*::\s*\w+\s*\()/
1926+
/\b\w+(?=\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*::\s*\w+\s*\()/
19171927
],
19181928
'keyword': keyword,
19191929
'number': {
@@ -2732,7 +2742,7 @@ Prism.languages.elixir = {
27322742
alias: 'class-name'
27332743
},
27342744
// Look-ahead prevents bad highlighting of the :: operator
2735-
'attr-name': /\w+\??:(?!:)/,
2745+
'attr-name': /\b\w+\??:(?!:)/,
27362746
'argument': {
27372747
// Look-behind prevents bad highlighting of the && operator
27382748
pattern: /(^|[^&])&\d+/,
@@ -2796,7 +2806,7 @@ Prism.languages.erlang = {
27962806
'keyword': /\b(?:fun|when|case|of|end|if|receive|after|try|catch)\b/,
27972807
'number': [
27982808
/\$\\?./,
2799-
/\d+#[a-z0-9]+/i,
2809+
/\b\d+#[a-z0-9]+/i,
28002810
/(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i
28012811
],
28022812
'function': /\b[a-z][\w@]*(?=\()/,
@@ -3034,7 +3044,7 @@ Prism.languages.julia = {
30343044
// https://docs.julialang.org/en/v1/manual/strings/#String-Basics-1
30353045
// https://docs.julialang.org/en/v1/manual/strings/#non-standard-string-literals-1
30363046
// https://docs.julialang.org/en/v1/manual/running-external-programs/#Running-External-Programs-1
3037-
pattern: /"""[\s\S]+?"""|\w*"(?:\\.|[^"\\\r\n])*"|(^|[^\w'])'(?:\\[^\r\n][^'\r\n]*|[^\\\r\n])'|`(?:[^\\`\r\n]|\\.)*`/,
3047+
pattern: /"""[\s\S]+?"""|(?:\b\w+)?"(?:\\.|[^"\\\r\n])*"|(^|[^\w'])'(?:\\[^\r\n][^'\r\n]*|[^\\\r\n])'|`(?:[^\\`\r\n]|\\.)*`/,
30383048
lookbehind: true,
30393049
greedy: true
30403050
},
@@ -3058,7 +3068,7 @@ Prism.languages.julia = {
30583068
},
30593069
'function': [
30603070
{
3061-
pattern: /(?:`[^\r\n`]+`|\w+)(?=\s*\()/,
3071+
pattern: /(?:`[^\r\n`]+`|\b\w+)(?=\s*\()/,
30623072
greedy: true
30633073
},
30643074
{
@@ -3088,7 +3098,7 @@ Prism.languages.julia = {
30883098
});
30893099
Prism.languages.insertBefore('kotlin', 'function', {
30903100
'label': {
3091-
pattern: /\w+@|@\w+/,
3101+
pattern: /\b\w+@|@\w+\b/,
30923102
alias: 'symbol'
30933103
}
30943104
});
@@ -3216,7 +3226,7 @@ Prism.languages.matlab = {
32163226
// FIXME We could handle imaginary numbers as a whole
32173227
'number': /(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[eE][+-]?\d+)?(?:[ij])?|\b[ij]\b/,
32183228
'keyword': /\b(?:break|case|catch|continue|else|elseif|end|for|function|if|inf|NaN|otherwise|parfor|pause|pi|return|switch|try|while)\b/,
3219-
'function': /(?!\d)\w+(?=\s*\()/,
3229+
'function': /\b(?!\d)\w+(?=\s*\()/,
32203230
'operator': /\.?[*^\/\\']|[+\-:@]|[<>=~]=?|&&?|\|\|?/,
32213231
'punctuation': /\.{3}|[.,;\[\](){}!]/
32223232
};
@@ -3943,7 +3953,7 @@ Prism.languages.python = {
39433953
lookbehind: true
39443954
},
39453955
'decorator': {
3946-
pattern: /(^\s*)@\w+(?:\.\w+)*/im,
3956+
pattern: /(^[\t ]*)@\w+(?:\.\w+)*/im,
39473957
lookbehind: true,
39483958
alias: ['annotation', 'punctuation'],
39493959
inside: {
@@ -3962,6 +3972,29 @@ Prism.languages.python['string-interpolation'].inside['interpolation'].inside.re
39623972

39633973
Prism.languages.py = Prism.languages.python;
39643974

3975+
Prism.languages.r = {
3976+
'comment': /#.*/,
3977+
'string': {
3978+
pattern: /(['"])(?:\\.|(?!\1)[^\\\r\n])*\1/,
3979+
greedy: true
3980+
},
3981+
'percent-operator': {
3982+
// Includes user-defined operators
3983+
// and %%, %*%, %/%, %in%, %o%, %x%
3984+
pattern: /%[^%\s]*%/,
3985+
alias: 'operator'
3986+
},
3987+
'boolean': /\b(?:TRUE|FALSE)\b/,
3988+
'ellipsis': /\.\.(?:\.|\d+)/,
3989+
'number': [
3990+
/\b(?:NaN|Inf)\b/,
3991+
/(?:\b0x[\dA-Fa-f]+(?:\.\d*)?|\b\d+(?:\.\d*)?|\B\.\d+)(?:[EePp][+-]?\d+)?[iL]?/
3992+
],
3993+
'keyword': /\b(?:if|else|repeat|while|function|for|in|next|break|NULL|NA|NA_integer_|NA_real_|NA_complex_|NA_character_)\b/,
3994+
'operator': /->?>?|<(?:=|<?-)?|[>=!]=?|::?|&&?|\|\|?|[+*\/^$@~]/,
3995+
'punctuation': /[(){}\[\],;]/
3996+
};
3997+
39653998
(function (Prism) {
39663999

39674000
var javascript = Prism.util.clone(Prism.languages.javascript);
@@ -4213,7 +4246,7 @@ Prism.languages.py = Prism.languages.python;
42134246
// https://doc.rust-lang.org/1.0.0/style/style/naming/README.html
42144247
'function': /\b[a-z_]\w*(?=\s*(?:::\s*<|\())/,
42154248
'macro': {
4216-
pattern: /\w+!/,
4249+
pattern: /\b\w+!/,
42174250
alias: 'property'
42184251
},
42194252
'constant': /\b[A-Z_][A-Z_\d]+\b/,
@@ -4283,7 +4316,7 @@ Prism.languages.insertBefore('scss', 'atrule', {
42834316
'keyword': [
42844317
/@(?:if|else(?: if)?|forward|for|each|while|import|use|extend|debug|warn|mixin|include|function|return|content)\b/i,
42854318
{
4286-
pattern: /( +)(?:from|through)(?= )/,
4319+
pattern: /( )(?:from|through)(?= )/,
42874320
lookbehind: true
42884321
}
42894322
]
@@ -4546,3 +4579,4 @@ Prism.languages.sql = {
45464579
Prism.languages.yml = Prism.languages.yaml;
45474580

45484581
}(Prism));
4582+

lib/docs/filters/r/clean_html.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ def call
5454
end
5555
end
5656

57+
css('pre').each do |node|
58+
node['data-language'] = 'r'
59+
end
60+
5761
doc
5862
end
5963
end

0 commit comments

Comments
 (0)