UNPKG

1.79 kBJavaScriptView Raw
1(function(Prism) {
2
3// Ignore comments starting with { to privilege string interpolation highlighting
4var comment = /#(?!\{).+/,
5 interpolation = {
6 pattern: /#\{[^}]+\}/,
7 alias: 'variable'
8 };
9
10Prism.languages.coffeescript = Prism.languages.extend('javascript', {
11 'comment': comment,
12 'string': [
13
14 // Strings are multiline
15 /'(?:\\?[^\\])*?'/,
16
17 {
18 // Strings are multiline
19 pattern: /"(?:\\?[^\\])*?"/,
20 inside: {
21 'interpolation': interpolation
22 }
23 }
24 ],
25 'keyword': /\b(and|break|by|catch|class|continue|debugger|delete|do|each|else|extend|extends|false|finally|for|if|in|instanceof|is|isnt|let|loop|namespace|new|no|not|null|of|off|on|or|own|return|super|switch|then|this|throw|true|try|typeof|undefined|unless|until|when|while|window|with|yes|yield)\b/,
26 'class-member': {
27 pattern: /@(?!\d)\w+/,
28 alias: 'variable'
29 }
30});
31
32Prism.languages.insertBefore('coffeescript', 'comment', {
33 'multiline-comment': {
34 pattern: /###[\s\S]+?###/,
35 alias: 'comment'
36 },
37
38 // Block regexp can contain comments and interpolation
39 'block-regex': {
40 pattern: /\/{3}[\s\S]*?\/{3}/,
41 alias: 'regex',
42 inside: {
43 'comment': comment,
44 'interpolation': interpolation
45 }
46 }
47});
48
49Prism.languages.insertBefore('coffeescript', 'string', {
50 'inline-javascript': {
51 pattern: /`(?:\\?[\s\S])*?`/,
52 inside: {
53 'delimiter': {
54 pattern: /^`|`$/,
55 alias: 'punctuation'
56 },
57 rest: Prism.languages.javascript
58 }
59 },
60
61 // Block strings
62 'multiline-string': [
63 {
64 pattern: /'''[\s\S]*?'''/,
65 alias: 'string'
66 },
67 {
68 pattern: /"""[\s\S]*?"""/,
69 alias: 'string',
70 inside: {
71 interpolation: interpolation
72 }
73 }
74 ]
75
76});
77
78Prism.languages.insertBefore('coffeescript', 'keyword', {
79 // Object property
80 'property': /(?!\d)\w+(?=\s*:(?!:))/
81});
82
83}(Prism));
\No newline at end of file