apache.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. */
  9. /** @type LanguageFn */
  10. function apache(hljs) {
  11. var NUMBER_REF = {className: 'number', begin: '[\\$%]\\d+'};
  12. var NUMBER = {className: 'number', begin: '\\d+'};
  13. var IP_ADDRESS = {
  14. className: "number",
  15. begin: '\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}(:\\d{1,5})?'
  16. };
  17. var PORT_NUMBER = {
  18. className: "number",
  19. begin: ":\\d{1,5}"
  20. };
  21. return {
  22. name: 'Apache config',
  23. aliases: ['apacheconf'],
  24. case_insensitive: true,
  25. contains: [
  26. hljs.HASH_COMMENT_MODE,
  27. {className: 'section', begin: '</?', end: '>',
  28. contains: [
  29. IP_ADDRESS,
  30. PORT_NUMBER,
  31. // low relevance prevents us from claming XML/HTML where this rule would
  32. // match strings inside of XML tags
  33. hljs.inherit(hljs.QUOTE_STRING_MODE, { relevance:0 })
  34. ]
  35. },
  36. {
  37. className: 'attribute',
  38. begin: /\w+/,
  39. relevance: 0,
  40. // keywords aren’t needed for highlighting per se, they only boost relevance
  41. // for a very generally defined mode (starts with a word, ends with line-end
  42. keywords: {
  43. nomarkup:
  44. 'order deny allow setenv rewriterule rewriteengine rewritecond documentroot ' +
  45. 'sethandler errordocument loadmodule options header listen serverroot ' +
  46. 'servername'
  47. },
  48. starts: {
  49. end: /$/,
  50. relevance: 0,
  51. keywords: {
  52. literal: 'on off all deny allow'
  53. },
  54. contains: [
  55. {
  56. className: 'meta',
  57. begin: '\\s\\[', end: '\\]$'
  58. },
  59. {
  60. className: 'variable',
  61. begin: '[\\$%]\\{', end: '\\}',
  62. contains: ['self', NUMBER_REF]
  63. },
  64. IP_ADDRESS,
  65. NUMBER,
  66. hljs.QUOTE_STRING_MODE
  67. ]
  68. }
  69. }
  70. ],
  71. illegal: /\S/
  72. };
  73. }
  74. module.exports = apache;