2024-01-16 21:26:16 +08:00
|
|
|
|
/*
|
|
|
|
|
Language: Apache config
|
|
|
|
|
Author: Ruslan Keba <rukeba@gmail.com>
|
|
|
|
|
Contributors: Ivan Sagalaev <maniac@softwaremaniacs.org>
|
|
|
|
|
Website: https://httpd.apache.org
|
|
|
|
|
Description: language definition for Apache configuration files (httpd.conf & .htaccess)
|
|
|
|
|
Category: common, config
|
|
|
|
|
Audit: 2020
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** @type LanguageFn */
|
|
|
|
|
function apache(hljs) {
|
|
|
|
|
const NUMBER_REF = {
|
|
|
|
|
className: 'number',
|
|
|
|
|
begin: /[$%]\d+/
|
|
|
|
|
};
|
|
|
|
|
const NUMBER = {
|
|
|
|
|
className: 'number',
|
|
|
|
|
begin: /\d+/
|
|
|
|
|
};
|
|
|
|
|
const IP_ADDRESS = {
|
|
|
|
|
className: "number",
|
|
|
|
|
begin: /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(:\d{1,5})?/
|
|
|
|
|
};
|
|
|
|
|
const PORT_NUMBER = {
|
|
|
|
|
className: "number",
|
|
|
|
|
begin: /:\d{1,5}/
|
|
|
|
|
};
|
2023-12-18 13:12:25 +08:00
|
|
|
|
return {
|
2024-01-16 21:26:16 +08:00
|
|
|
|
name: 'Apache config',
|
|
|
|
|
aliases: [ 'apacheconf' ],
|
2023-12-18 13:12:25 +08:00
|
|
|
|
case_insensitive: true,
|
|
|
|
|
contains: [
|
|
|
|
|
hljs.HASH_COMMENT_MODE,
|
2024-01-16 21:26:16 +08:00
|
|
|
|
{
|
|
|
|
|
className: 'section',
|
|
|
|
|
begin: /<\/?/,
|
|
|
|
|
end: />/,
|
|
|
|
|
contains: [
|
|
|
|
|
IP_ADDRESS,
|
|
|
|
|
PORT_NUMBER,
|
|
|
|
|
// low relevance prevents us from claming XML/HTML where this rule would
|
|
|
|
|
// match strings inside of XML tags
|
|
|
|
|
hljs.inherit(hljs.QUOTE_STRING_MODE, { relevance: 0 })
|
|
|
|
|
]
|
|
|
|
|
},
|
2023-12-18 13:12:25 +08:00
|
|
|
|
{
|
|
|
|
|
className: 'attribute',
|
|
|
|
|
begin: /\w+/,
|
|
|
|
|
relevance: 0,
|
|
|
|
|
// keywords aren’t needed for highlighting per se, they only boost relevance
|
|
|
|
|
// for a very generally defined mode (starts with a word, ends with line-end
|
|
|
|
|
keywords: {
|
|
|
|
|
nomarkup:
|
|
|
|
|
'order deny allow setenv rewriterule rewriteengine rewritecond documentroot ' +
|
|
|
|
|
'sethandler errordocument loadmodule options header listen serverroot ' +
|
|
|
|
|
'servername'
|
|
|
|
|
},
|
|
|
|
|
starts: {
|
|
|
|
|
end: /$/,
|
|
|
|
|
relevance: 0,
|
2024-01-16 21:26:16 +08:00
|
|
|
|
keywords: { literal: 'on off all deny allow' },
|
2023-12-18 13:12:25 +08:00
|
|
|
|
contains: [
|
|
|
|
|
{
|
|
|
|
|
className: 'meta',
|
2024-01-16 21:26:16 +08:00
|
|
|
|
begin: /\s\[/,
|
|
|
|
|
end: /\]$/
|
2023-12-18 13:12:25 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
className: 'variable',
|
2024-01-16 21:26:16 +08:00
|
|
|
|
begin: /[\$%]\{/,
|
|
|
|
|
end: /\}/,
|
|
|
|
|
contains: [
|
|
|
|
|
'self',
|
|
|
|
|
NUMBER_REF
|
|
|
|
|
]
|
2023-12-18 13:12:25 +08:00
|
|
|
|
},
|
2024-01-16 21:26:16 +08:00
|
|
|
|
IP_ADDRESS,
|
2023-12-18 13:12:25 +08:00
|
|
|
|
NUMBER,
|
|
|
|
|
hljs.QUOTE_STRING_MODE
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
illegal: /\S/
|
|
|
|
|
};
|
2024-01-16 21:26:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = apache;
|