htmlbars.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 =
  11. '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';
  12. var ATTR_ASSIGNMENT = {
  13. illegal: /\}\}/,
  14. begin: /[a-zA-Z0-9_]+=/,
  15. returnBegin: true,
  16. relevance: 0,
  17. contains: [
  18. {
  19. className: 'attr',
  20. begin: /[a-zA-Z0-9_]+/
  21. }
  22. ]
  23. };
  24. var TAG_INNARDS = {
  25. endsWithParent: true,
  26. relevance: 0,
  27. keywords: {
  28. keyword: 'as',
  29. built_in: BUILT_INS
  30. },
  31. contains: [hljs.QUOTE_STRING_MODE, ATTR_ASSIGNMENT, hljs.NUMBER_MODE]
  32. };
  33. return {
  34. name: 'HTMLBars',
  35. case_insensitive: true,
  36. subLanguage: 'xml',
  37. contains: [
  38. hljs.COMMENT('{{!(--)?', '(--)?}}'),
  39. {
  40. className: 'template-tag',
  41. begin: /\{\{[#\/]/,
  42. end: /\}\}/,
  43. contains: [
  44. {
  45. className: 'name',
  46. begin: /[a-zA-Z\.\-]+/,
  47. keywords: {
  48. 'builtin-name': BUILT_INS
  49. },
  50. starts: TAG_INNARDS
  51. }
  52. ]
  53. },
  54. {
  55. className: 'template-variable',
  56. begin: /\{\{[a-zA-Z][a-zA-Z\-]+/,
  57. end: /\}\}/,
  58. keywords: {
  59. keyword: 'as',
  60. built_in: BUILT_INS
  61. },
  62. contains: [hljs.QUOTE_STRING_MODE]
  63. }
  64. ]
  65. };
  66. }