nginx.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. module.exports = function(hljs) {
  2. var VAR = {
  3. className: 'variable',
  4. variants: [
  5. {begin: /\$\d+/},
  6. {begin: /\$\{/, end: /}/},
  7. {begin: '[\\$\\@]' + hljs.UNDERSCORE_IDENT_RE}
  8. ]
  9. };
  10. var DEFAULT = {
  11. endsWithParent: true,
  12. lexemes: '[a-z/_]+',
  13. keywords: {
  14. literal:
  15. 'on off yes no true false none blocked debug info notice warn error crit ' +
  16. 'select break last permanent redirect kqueue rtsig epoll poll /dev/poll'
  17. },
  18. relevance: 0,
  19. illegal: '=>',
  20. contains: [
  21. hljs.HASH_COMMENT_MODE,
  22. {
  23. className: 'string',
  24. contains: [hljs.BACKSLASH_ESCAPE, VAR],
  25. variants: [
  26. {begin: /"/, end: /"/},
  27. {begin: /'/, end: /'/}
  28. ]
  29. },
  30. // this swallows entire URLs to avoid detecting numbers within
  31. {
  32. begin: '([a-z]+):/', end: '\\s', endsWithParent: true, excludeEnd: true,
  33. contains: [VAR]
  34. },
  35. {
  36. className: 'regexp',
  37. contains: [hljs.BACKSLASH_ESCAPE, VAR],
  38. variants: [
  39. {begin: "\\s\\^", end: "\\s|{|;", returnEnd: true},
  40. // regexp locations (~, ~*)
  41. {begin: "~\\*?\\s+", end: "\\s|{|;", returnEnd: true},
  42. // *.example.com
  43. {begin: "\\*(\\.[a-z\\-]+)+"},
  44. // sub.example.*
  45. {begin: "([a-z\\-]+\\.)+\\*"}
  46. ]
  47. },
  48. // IP
  49. {
  50. className: 'number',
  51. begin: '\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}(:\\d{1,5})?\\b'
  52. },
  53. // units
  54. {
  55. className: 'number',
  56. begin: '\\b\\d+[kKmMgGdshdwy]*\\b',
  57. relevance: 0
  58. },
  59. VAR
  60. ]
  61. };
  62. return {
  63. aliases: ['nginxconf'],
  64. contains: [
  65. hljs.HASH_COMMENT_MODE,
  66. {
  67. begin: hljs.UNDERSCORE_IDENT_RE + '\\s+{', returnBegin: true,
  68. end: '{',
  69. contains: [
  70. {
  71. className: 'section',
  72. begin: hljs.UNDERSCORE_IDENT_RE
  73. }
  74. ],
  75. relevance: 0
  76. },
  77. {
  78. begin: hljs.UNDERSCORE_IDENT_RE + '\\s', end: ';|{', returnBegin: true,
  79. contains: [
  80. {
  81. className: 'attribute',
  82. begin: hljs.UNDERSCORE_IDENT_RE,
  83. starts: DEFAULT
  84. }
  85. ],
  86. relevance: 0
  87. }
  88. ],
  89. illegal: '[^\\s\\}]'
  90. };
  91. };