[d24f17c] | 1 | (function (Prism) {
|
---|
| 2 |
|
---|
| 3 | // Ignore comments starting with { to privilege string interpolation highlighting
|
---|
| 4 | var comment = /#(?!\{).+/;
|
---|
| 5 | var interpolation = {
|
---|
| 6 | pattern: /#\{[^}]+\}/,
|
---|
| 7 | alias: 'variable'
|
---|
| 8 | };
|
---|
| 9 |
|
---|
| 10 | Prism.languages.coffeescript = Prism.languages.extend('javascript', {
|
---|
| 11 | 'comment': comment,
|
---|
| 12 | 'string': [
|
---|
| 13 |
|
---|
| 14 | // Strings are multiline
|
---|
| 15 | {
|
---|
| 16 | pattern: /'(?:\\[\s\S]|[^\\'])*'/,
|
---|
| 17 | greedy: true
|
---|
| 18 | },
|
---|
| 19 |
|
---|
| 20 | {
|
---|
| 21 | // Strings are multiline
|
---|
| 22 | pattern: /"(?:\\[\s\S]|[^\\"])*"/,
|
---|
| 23 | greedy: true,
|
---|
| 24 | inside: {
|
---|
| 25 | 'interpolation': interpolation
|
---|
| 26 | }
|
---|
| 27 | }
|
---|
| 28 | ],
|
---|
| 29 | '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/,
|
---|
| 30 | 'class-member': {
|
---|
| 31 | pattern: /@(?!\d)\w+/,
|
---|
| 32 | alias: 'variable'
|
---|
| 33 | }
|
---|
| 34 | });
|
---|
| 35 |
|
---|
| 36 | Prism.languages.insertBefore('coffeescript', 'comment', {
|
---|
| 37 | 'multiline-comment': {
|
---|
| 38 | pattern: /###[\s\S]+?###/,
|
---|
| 39 | alias: 'comment'
|
---|
| 40 | },
|
---|
| 41 |
|
---|
| 42 | // Block regexp can contain comments and interpolation
|
---|
| 43 | 'block-regex': {
|
---|
| 44 | pattern: /\/{3}[\s\S]*?\/{3}/,
|
---|
| 45 | alias: 'regex',
|
---|
| 46 | inside: {
|
---|
| 47 | 'comment': comment,
|
---|
| 48 | 'interpolation': interpolation
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 | });
|
---|
| 52 |
|
---|
| 53 | Prism.languages.insertBefore('coffeescript', 'string', {
|
---|
| 54 | 'inline-javascript': {
|
---|
| 55 | pattern: /`(?:\\[\s\S]|[^\\`])*`/,
|
---|
| 56 | inside: {
|
---|
| 57 | 'delimiter': {
|
---|
| 58 | pattern: /^`|`$/,
|
---|
| 59 | alias: 'punctuation'
|
---|
| 60 | },
|
---|
| 61 | 'script': {
|
---|
| 62 | pattern: /[\s\S]+/,
|
---|
| 63 | alias: 'language-javascript',
|
---|
| 64 | inside: Prism.languages.javascript
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 | },
|
---|
| 68 |
|
---|
| 69 | // Block strings
|
---|
| 70 | 'multiline-string': [
|
---|
| 71 | {
|
---|
| 72 | pattern: /'''[\s\S]*?'''/,
|
---|
| 73 | greedy: true,
|
---|
| 74 | alias: 'string'
|
---|
| 75 | },
|
---|
| 76 | {
|
---|
| 77 | pattern: /"""[\s\S]*?"""/,
|
---|
| 78 | greedy: true,
|
---|
| 79 | alias: 'string',
|
---|
| 80 | inside: {
|
---|
| 81 | interpolation: interpolation
|
---|
| 82 | }
|
---|
| 83 | }
|
---|
| 84 | ]
|
---|
| 85 |
|
---|
| 86 | });
|
---|
| 87 |
|
---|
| 88 | Prism.languages.insertBefore('coffeescript', 'keyword', {
|
---|
| 89 | // Object property
|
---|
| 90 | 'property': /(?!\d)\w+(?=\s*:(?!:))/
|
---|
| 91 | });
|
---|
| 92 |
|
---|
| 93 | delete Prism.languages.coffeescript['template-string'];
|
---|
| 94 |
|
---|
| 95 | Prism.languages.coffee = Prism.languages.coffeescript;
|
---|
| 96 | }(Prism));
|
---|