properties.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. module.exports = function(hljs) {
  2. // whitespaces: space, tab, formfeed
  3. var WS0 = '[ \\t\\f]*';
  4. var WS1 = '[ \\t\\f]+';
  5. // delimiter
  6. var DELIM = '(' + WS0+'[:=]'+WS0+ '|' + WS1 + ')';
  7. var KEY_ALPHANUM = '([^\\\\\\W:= \\t\\f\\n]|\\\\.)+';
  8. var KEY_OTHER = '([^\\\\:= \\t\\f\\n]|\\\\.)+';
  9. var DELIM_AND_VALUE = {
  10. // skip DELIM
  11. end: DELIM,
  12. relevance: 0,
  13. starts: {
  14. // value: everything until end of line (again, taking into account backslashes)
  15. className: 'string',
  16. end: /$/,
  17. relevance: 0,
  18. contains: [
  19. { begin: '\\\\\\n' }
  20. ]
  21. }
  22. };
  23. return {
  24. case_insensitive: true,
  25. illegal: /\S/,
  26. contains: [
  27. hljs.COMMENT('^\\s*[!#]', '$'),
  28. // key: everything until whitespace or = or : (taking into account backslashes)
  29. // case of a "normal" key
  30. {
  31. begin: KEY_ALPHANUM + DELIM,
  32. returnBegin: true,
  33. contains: [
  34. {
  35. className: 'attr',
  36. begin: KEY_ALPHANUM,
  37. endsParent: true,
  38. relevance: 0
  39. }
  40. ],
  41. starts: DELIM_AND_VALUE
  42. },
  43. // case of key containing non-alphanumeric chars => relevance = 0
  44. {
  45. begin: KEY_OTHER + DELIM,
  46. returnBegin: true,
  47. relevance: 0,
  48. contains: [
  49. {
  50. className: 'meta',
  51. begin: KEY_OTHER,
  52. endsParent: true,
  53. relevance: 0
  54. }
  55. ],
  56. starts: DELIM_AND_VALUE
  57. },
  58. // case of an empty key
  59. {
  60. className: 'attr',
  61. relevance: 0,
  62. begin: KEY_OTHER + WS0 + '$'
  63. }
  64. ]
  65. };
  66. };