htmlbars.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. Language: HTMLBars
  3. Requires: xml.js
  4. Author: Michael Johnston <[email protected]>
  5. Description: Matcher for HTMLBars
  6. Category: template
  7. */
  8. function(hljs) {
  9. var BUILT_INS = 'action collection component concat debugger each each-in else get hash if input link-to loc log mut outlet partial query-params render textarea unbound unless with yield view';
  10. var ATTR_ASSIGNMENT = {
  11. illegal: /\}\}/,
  12. begin: /[a-zA-Z0-9_]+=/,
  13. returnBegin: true,
  14. relevance: 0,
  15. contains: [
  16. {
  17. className: 'attr', begin: /[a-zA-Z0-9_]+/
  18. }
  19. ]
  20. };
  21. var SUB_EXPR = {
  22. illegal: /\}\}/,
  23. begin: /\)/, end: /\)/,
  24. contains: [
  25. {
  26. begin: /[a-zA-Z\.\-]+/,
  27. keywords: {built_in: BUILT_INS},
  28. starts: {
  29. endsWithParent: true, relevance: 0,
  30. contains: [
  31. hljs.QUOTE_STRING_MODE,
  32. ]
  33. }
  34. }
  35. ]
  36. };
  37. var TAG_INNARDS = {
  38. endsWithParent: true, relevance: 0,
  39. keywords: {keyword: 'as', built_in: BUILT_INS},
  40. contains: [
  41. hljs.QUOTE_STRING_MODE,
  42. ATTR_ASSIGNMENT,
  43. hljs.NUMBER_MODE
  44. ]
  45. };
  46. return {
  47. case_insensitive: true,
  48. subLanguage: 'xml',
  49. contains: [
  50. hljs.COMMENT('{{!(--)?', '(--)?}}'),
  51. {
  52. className: 'template-tag',
  53. begin: /\{\{[#\/]/, end: /\}\}/,
  54. contains: [
  55. {
  56. className: 'name',
  57. begin: /[a-zA-Z\.\-]+/,
  58. keywords: {'builtin-name': BUILT_INS},
  59. starts: TAG_INNARDS
  60. }
  61. ]
  62. },
  63. {
  64. className: 'template-variable',
  65. begin: /\{\{[a-zA-Z][a-zA-Z\-]+/, end: /\}\}/,
  66. keywords: {keyword: 'as', built_in: BUILT_INS},
  67. contains: [
  68. hljs.QUOTE_STRING_MODE
  69. ]
  70. }
  71. ]
  72. };
  73. }