prism-coffeescript.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. /'(?:\\?[\s\S])*?'/,
  13. {
  14. // Strings are multiline
  15. pattern: /"(?:\\?[\s\S])*?"/,
  16. inside: {
  17. 'interpolation': interpolation
  18. }
  19. }
  20. ],
  21. '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/,
  22. 'class-member': {
  23. pattern: /@(?!\d)\w+/,
  24. alias: 'variable'
  25. }
  26. });
  27. Prism.languages.insertBefore('coffeescript', 'comment', {
  28. 'multiline-comment': {
  29. pattern: /###[\s\S]+?###/,
  30. alias: 'comment'
  31. },
  32. // Block regexp can contain comments and interpolation
  33. 'block-regex': {
  34. pattern: /\/{3}[\s\S]*?\/{3}/,
  35. alias: 'regex',
  36. inside: {
  37. 'comment': comment,
  38. 'interpolation': interpolation
  39. }
  40. }
  41. });
  42. Prism.languages.insertBefore('coffeescript', 'string', {
  43. 'inline-javascript': {
  44. pattern: /`(?:\\?[\s\S])*?`/,
  45. inside: {
  46. 'delimiter': {
  47. pattern: /^`|`$/,
  48. alias: 'punctuation'
  49. },
  50. rest: Prism.languages.javascript
  51. }
  52. },
  53. // Block strings
  54. 'multiline-string': [
  55. {
  56. pattern: /'''[\s\S]*?'''/,
  57. alias: 'string'
  58. },
  59. {
  60. pattern: /"""[\s\S]*?"""/,
  61. alias: 'string',
  62. inside: {
  63. interpolation: interpolation
  64. }
  65. }
  66. ]
  67. });
  68. Prism.languages.insertBefore('coffeescript', 'keyword', {
  69. // Object property
  70. 'property': /(?!\d)\w+(?=\s*:(?!:))/
  71. });
  72. }(Prism));