htmlbars.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. Language: HTMLBars
  3. Requires: xml.js
  4. Author: Michael Johnston <lastobelus@gmail.com>
  5. Description: Matcher for HTMLBars
  6. Website: https://github.com/tildeio/htmlbars
  7. Category: template
  8. */
  9. export default function(hljs) {
  10. 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';
  11. var ATTR_ASSIGNMENT = {
  12. illegal: /\}\}/,
  13. begin: /[a-zA-Z0-9_]+=/,
  14. returnBegin: true,
  15. relevance: 0,
  16. contains: [
  17. {
  18. className: 'attr', begin: /[a-zA-Z0-9_]+/
  19. }
  20. ]
  21. };
  22. var SUB_EXPR = {
  23. illegal: /\}\}/,
  24. begin: /\)/, end: /\)/,
  25. contains: [
  26. {
  27. begin: /[a-zA-Z\.\-]+/,
  28. keywords: {built_in: BUILT_INS},
  29. starts: {
  30. endsWithParent: true, relevance: 0,
  31. contains: [
  32. hljs.QUOTE_STRING_MODE,
  33. ]
  34. }
  35. }
  36. ]
  37. };
  38. var TAG_INNARDS = {
  39. endsWithParent: true, relevance: 0,
  40. keywords: {keyword: 'as', built_in: BUILT_INS},
  41. contains: [
  42. hljs.QUOTE_STRING_MODE,
  43. ATTR_ASSIGNMENT,
  44. hljs.NUMBER_MODE
  45. ]
  46. };
  47. return {
  48. name: 'HTMLBars',
  49. case_insensitive: true,
  50. subLanguage: 'xml',
  51. contains: [
  52. hljs.COMMENT('{{!(--)?', '(--)?}}'),
  53. {
  54. className: 'template-tag',
  55. begin: /\{\{[#\/]/, end: /\}\}/,
  56. contains: [
  57. {
  58. className: 'name',
  59. begin: /[a-zA-Z\.\-]+/,
  60. keywords: {'builtin-name': BUILT_INS},
  61. starts: TAG_INNARDS
  62. }
  63. ]
  64. },
  65. {
  66. className: 'template-variable',
  67. begin: /\{\{[a-zA-Z][a-zA-Z\-]+/, end: /\}\}/,
  68. keywords: {keyword: 'as', built_in: BUILT_INS},
  69. contains: [
  70. hljs.QUOTE_STRING_MODE
  71. ]
  72. }
  73. ]
  74. };
  75. }