nginx.js 2.5 KB

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