UNPKG

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