apache.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. Language: Apache config
  3. Author: Ruslan Keba <rukeba@gmail.com>
  4. Contributors: Ivan Sagalaev <maniac@softwaremaniacs.org>
  5. Website: https://httpd.apache.org
  6. Description: language definition for Apache configuration files (httpd.conf & .htaccess)
  7. Category: config, web
  8. Audit: 2020
  9. */
  10. /** @type LanguageFn */
  11. function apache(hljs) {
  12. const NUMBER_REF = {
  13. className: 'number',
  14. begin: /[$%]\d+/
  15. };
  16. const NUMBER = {
  17. className: 'number',
  18. begin: /\b\d+/
  19. };
  20. const IP_ADDRESS = {
  21. className: "number",
  22. begin: /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(:\d{1,5})?/
  23. };
  24. const PORT_NUMBER = {
  25. className: "number",
  26. begin: /:\d{1,5}/
  27. };
  28. return {
  29. name: 'Apache config',
  30. aliases: [ 'apacheconf' ],
  31. case_insensitive: true,
  32. contains: [
  33. hljs.HASH_COMMENT_MODE,
  34. {
  35. className: 'section',
  36. begin: /<\/?/,
  37. end: />/,
  38. contains: [
  39. IP_ADDRESS,
  40. PORT_NUMBER,
  41. // low relevance prevents us from claming XML/HTML where this rule would
  42. // match strings inside of XML tags
  43. hljs.inherit(hljs.QUOTE_STRING_MODE, { relevance: 0 })
  44. ]
  45. },
  46. {
  47. className: 'attribute',
  48. begin: /\w+/,
  49. relevance: 0,
  50. // keywords aren’t needed for highlighting per se, they only boost relevance
  51. // for a very generally defined mode (starts with a word, ends with line-end
  52. keywords: { _: [
  53. "order",
  54. "deny",
  55. "allow",
  56. "setenv",
  57. "rewriterule",
  58. "rewriteengine",
  59. "rewritecond",
  60. "documentroot",
  61. "sethandler",
  62. "errordocument",
  63. "loadmodule",
  64. "options",
  65. "header",
  66. "listen",
  67. "serverroot",
  68. "servername"
  69. ] },
  70. starts: {
  71. end: /$/,
  72. relevance: 0,
  73. keywords: { literal: 'on off all deny allow' },
  74. contains: [
  75. {
  76. className: 'meta',
  77. begin: /\s\[/,
  78. end: /\]$/
  79. },
  80. {
  81. className: 'variable',
  82. begin: /[\$%]\{/,
  83. end: /\}/,
  84. contains: [
  85. 'self',
  86. NUMBER_REF
  87. ]
  88. },
  89. IP_ADDRESS,
  90. NUMBER,
  91. hljs.QUOTE_STRING_MODE
  92. ]
  93. }
  94. }
  95. ],
  96. illegal: /\S/
  97. };
  98. }
  99. export { apache as default };