prism-coffeescript.js 2.0 KB

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