handlebars.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. module.exports = function (hljs) {
  2. var BUILT_INS = {'builtin-name': 'each in with if else unless bindattr action collection debugger log outlet template unbound view yield lookup'};
  3. var IDENTIFIER_PLAIN_OR_QUOTED = {
  4. begin: /".*?"|'.*?'|\[.*?\]|\w+/
  5. };
  6. var EXPRESSION_OR_HELPER_CALL = hljs.inherit(IDENTIFIER_PLAIN_OR_QUOTED, {
  7. keywords: BUILT_INS,
  8. starts: {
  9. // helper params
  10. endsWithParent: true,
  11. relevance: 0,
  12. contains: [hljs.inherit(IDENTIFIER_PLAIN_OR_QUOTED, {relevance: 0})]
  13. }
  14. });
  15. var BLOCK_MUSTACHE_CONTENTS = hljs.inherit(EXPRESSION_OR_HELPER_CALL, {
  16. className: 'name'
  17. });
  18. var BASIC_MUSTACHE_CONTENTS = hljs.inherit(EXPRESSION_OR_HELPER_CALL, {
  19. // relevance 0 for backward compatibility concerning auto-detection
  20. relevance: 0
  21. });
  22. var ESCAPE_MUSTACHE_WITH_PRECEEDING_BACKSLASH = {begin: /\\\{\{/, skip: true};
  23. var PREVENT_ESCAPE_WITH_ANOTHER_PRECEEDING_BACKSLASH = {begin: /\\\\(?=\{\{)/, skip: true};
  24. return {
  25. aliases: ['hbs', 'html.hbs', 'html.handlebars'],
  26. case_insensitive: true,
  27. subLanguage: 'xml',
  28. contains: [
  29. ESCAPE_MUSTACHE_WITH_PRECEEDING_BACKSLASH,
  30. PREVENT_ESCAPE_WITH_ANOTHER_PRECEEDING_BACKSLASH,
  31. hljs.COMMENT(/\{\{!--/, /--\}\}/),
  32. hljs.COMMENT(/\{\{!/, /\}\}/),
  33. {
  34. // open raw block "{{{{raw}}}} content not evaluated {{{{/raw}}}}"
  35. className: 'template-tag',
  36. begin: /\{\{\{\{(?!\/)/, end: /\}\}\}\}/,
  37. contains: [BLOCK_MUSTACHE_CONTENTS],
  38. starts: {end: /\{\{\{\{\//, returnEnd: true, subLanguage: 'xml'}
  39. },
  40. {
  41. // close raw block
  42. className: 'template-tag',
  43. begin: /\{\{\{\{\//, end: /\}\}\}\}/,
  44. contains: [BLOCK_MUSTACHE_CONTENTS]
  45. },
  46. {
  47. // open block statement
  48. className: 'template-tag',
  49. begin: /\{\{[#\/]/, end: /\}\}/,
  50. contains: [BLOCK_MUSTACHE_CONTENTS],
  51. },
  52. {
  53. // template variable or helper-call that is NOT html-escaped
  54. className: 'template-variable',
  55. begin: /\{\{\{/, end: /\}\}\}/,
  56. keywords: BUILT_INS,
  57. contains: [BASIC_MUSTACHE_CONTENTS]
  58. },
  59. {
  60. // template variable or helper-call that is html-escaped
  61. className: 'template-variable',
  62. begin: /\{\{/, end: /\}\}/,
  63. keywords: BUILT_INS,
  64. contains: [BASIC_MUSTACHE_CONTENTS]
  65. }
  66. ]
  67. };
  68. };