nginx.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. const VAR = {
  10. className: 'variable',
  11. variants: [
  12. {
  13. begin: /\$\d+/
  14. },
  15. {
  16. begin: /\$\{/,
  17. end: /\}/
  18. },
  19. {
  20. begin: /[$@]/ + hljs.UNDERSCORE_IDENT_RE
  21. }
  22. ]
  23. };
  24. const DEFAULT = {
  25. endsWithParent: true,
  26. keywords: {
  27. $pattern: '[a-z/_]+',
  28. literal:
  29. 'on off yes no true false none blocked debug info notice warn error crit ' +
  30. 'select break last permanent redirect kqueue rtsig epoll poll /dev/poll'
  31. },
  32. relevance: 0,
  33. illegal: '=>',
  34. contains: [
  35. hljs.HASH_COMMENT_MODE,
  36. {
  37. className: 'string',
  38. contains: [
  39. hljs.BACKSLASH_ESCAPE,
  40. VAR
  41. ],
  42. variants: [
  43. {
  44. begin: /"/,
  45. end: /"/
  46. },
  47. {
  48. begin: /'/,
  49. end: /'/
  50. }
  51. ]
  52. },
  53. // this swallows entire URLs to avoid detecting numbers within
  54. {
  55. begin: '([a-z]+):/',
  56. end: '\\s',
  57. endsWithParent: true,
  58. excludeEnd: true,
  59. contains: [ VAR ]
  60. },
  61. {
  62. className: 'regexp',
  63. contains: [
  64. hljs.BACKSLASH_ESCAPE,
  65. VAR
  66. ],
  67. variants: [
  68. {
  69. begin: "\\s\\^",
  70. end: "\\s|\\{|;",
  71. returnEnd: true
  72. },
  73. // regexp locations (~, ~*)
  74. {
  75. begin: "~\\*?\\s+",
  76. end: "\\s|\\{|;",
  77. returnEnd: true
  78. },
  79. // *.example.com
  80. {
  81. begin: "\\*(\\.[a-z\\-]+)+"
  82. },
  83. // sub.example.*
  84. {
  85. begin: "([a-z\\-]+\\.)+\\*"
  86. }
  87. ]
  88. },
  89. // IP
  90. {
  91. className: 'number',
  92. begin: '\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}(:\\d{1,5})?\\b'
  93. },
  94. // units
  95. {
  96. className: 'number',
  97. begin: '\\b\\d+[kKmMgGdshdwy]*\\b',
  98. relevance: 0
  99. },
  100. VAR
  101. ]
  102. };
  103. return {
  104. name: 'Nginx config',
  105. aliases: [ 'nginxconf' ],
  106. contains: [
  107. hljs.HASH_COMMENT_MODE,
  108. {
  109. begin: hljs.UNDERSCORE_IDENT_RE + '\\s+\\{',
  110. returnBegin: true,
  111. end: /\{/,
  112. contains: [
  113. {
  114. className: 'section',
  115. begin: hljs.UNDERSCORE_IDENT_RE
  116. }
  117. ],
  118. relevance: 0
  119. },
  120. {
  121. begin: hljs.UNDERSCORE_IDENT_RE + '\\s',
  122. end: ';|\\{',
  123. returnBegin: true,
  124. contains: [
  125. {
  126. className: 'attribute',
  127. begin: hljs.UNDERSCORE_IDENT_RE,
  128. starts: DEFAULT
  129. }
  130. ],
  131. relevance: 0
  132. }
  133. ],
  134. illegal: '[^\\s\\}]'
  135. };
  136. }
  137. module.exports = nginx;