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