apache.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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: common, config
  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: /\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. nomarkup:
  54. 'order deny allow setenv rewriterule rewriteengine rewritecond documentroot ' +
  55. 'sethandler errordocument loadmodule options header listen serverroot ' +
  56. 'servername'
  57. },
  58. starts: {
  59. end: /$/,
  60. relevance: 0,
  61. keywords: { literal: 'on off all deny allow' },
  62. contains: [
  63. {
  64. className: 'meta',
  65. begin: /\s\[/,
  66. end: /\]$/
  67. },
  68. {
  69. className: 'variable',
  70. begin: /[\$%]\{/,
  71. end: /\}/,
  72. contains: [
  73. 'self',
  74. NUMBER_REF
  75. ]
  76. },
  77. IP_ADDRESS,
  78. NUMBER,
  79. hljs.QUOTE_STRING_MODE
  80. ]
  81. }
  82. }
  83. ],
  84. illegal: /\S/
  85. };
  86. }
  87. module.exports = apache;