Skip to content

Commit a1c028c

Browse files
committed
Merge pull request #614 from Golmote/prism-elixir
Add support for elixir
2 parents 4eaf771 + ea49b66 commit a1c028c

17 files changed

+922
-2
lines changed

components.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ var components = {
127127
"title": "Eiffel",
128128
"owner": "Conaclos"
129129
},
130+
"elixir": {
131+
"title": "elixir",
132+
"owner": "Golmote"
133+
},
130134
"erlang": {
131135
"title": "Erlang",
132136
"owner": "Golmote"

components/prism-elixir.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
Prism.languages.elixir = {
2+
// Negative look-ahead is needed for string interpolation
3+
'comment': /#(?!\{).*/,
4+
// ~r"""foo""", ~r'''foo''', ~r/foo/, ~r|foo|, ~r"foo", ~r'foo', ~r(foo), ~r[foo], ~r{foo}, ~r<foo>
5+
'regex': /~[rR](?:("""|'''|[\/|"'])(?:\\.|(?!\1)[^\\])+\1|\((?:\\\)|[^)])+\)|\[(?:\\\]|[^\]])+\]|\{(?:\\\}|[^}])+\}|<(?:\\>|[^>])+>)[uismxfr]*/,
6+
'string': [
7+
{
8+
// ~s"""foo""", ~s'''foo''', ~s/foo/, ~s|foo|, ~s"foo", ~s'foo', ~s(foo), ~s[foo], ~s{foo}, ~s<foo>
9+
pattern: /~[cCsSwW](?:("""|'''|[\/|"'])(?:\\.|(?!\1)[^\\])+\1|\((?:\\\)|[^)])+\)|\[(?:\\\]|[^\]])+\]|\{(?:\\\}|#\{[^}]+\}|[^}])+\}|<(?:\\>|[^>])+>)[csa]?/,
10+
inside: {
11+
// See interpolation below
12+
}
13+
},
14+
{
15+
pattern: /("""|''')[\s\S]*?\1/,
16+
inside: {
17+
// See interpolation below
18+
}
19+
},
20+
{
21+
// Multi-line strings are allowed
22+
pattern: /("|')(?:\\[\s\S]|(?!\1)[^\\])*\1/,
23+
inside: {
24+
// See interpolation below
25+
}
26+
}
27+
],
28+
'atom': {
29+
// Look-behind prevents bad highlighting of the :: operator
30+
pattern: /(^|[^:]):\w+/,
31+
lookbehind: true,
32+
alias: 'symbol'
33+
},
34+
// Look-ahead prevents bad highlighting of the :: operator
35+
'attr-name': /\w+:(?!:)/,
36+
'capture': {
37+
// Look-behind prevents bad highlighting of the && operator
38+
pattern: /(^|[^&])&(?:[^&\s\d()][^\s()]*|(?=\())/,
39+
lookbehind: true,
40+
alias: 'function'
41+
},
42+
'argument': {
43+
// Look-behind prevents bad highlighting of the && operator
44+
pattern: /(^|[^&])&\d+/,
45+
lookbehind: true,
46+
alias: 'variable'
47+
},
48+
'attribute': {
49+
pattern: /@[\S]+/,
50+
alias: 'variable'
51+
},
52+
'number': /\b(?:0[box][a-f\d_]+|\d[\d_]*)(?:\.[\d_]+)?(?:e[+-]?[\d_]+)?\b/i,
53+
'keyword': /\b(?:after|alias|and|case|catch|cond|def(?:callback|exception|impl|module|p|protocol|struct)?|do|else|end|fn|for|if|import|not|or|require|rescue|try|unless|use|when)\b/,
54+
'boolean': /\b(?:true|false|nil)\b/,
55+
'operator': [
56+
/\bin\b|&&?|\|[|>]?|\\\\|::|\.\.\.?|\+\+?|-[->]?|<[-=>]|>=|!==?|\B!|=(?:==?|[>~])?|[*\/^]/,
57+
{
58+
// We don't want to match <<
59+
pattern: /([^<])<(?!<)/,
60+
lookbehind: true
61+
},
62+
{
63+
// We don't want to match >>
64+
pattern: /([^>])>(?!>)/,
65+
lookbehind: true
66+
}
67+
],
68+
'punctuation': /<<|>>|[.,%\[\]{}()]/
69+
};
70+
71+
Prism.languages.elixir.string.forEach(function(o) {
72+
o.inside = {
73+
'interpolation': {
74+
pattern: /#\{[^}]+\}/,
75+
inside: {
76+
'delimiter': {
77+
pattern: /^#\{|\}$/,
78+
alias: 'punctuation'
79+
},
80+
rest: Prism.util.clone(Prism.languages.elixir)
81+
}
82+
}
83+
};
84+
});

components/prism-elixir.min.js

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

0 commit comments

Comments
 (0)