source: node_modules/highlight.js/lib/languages/accesslog.js@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 2.5 KB
RevLine 
[d24f17c]1/**
2 * @param {string} value
3 * @returns {RegExp}
4 * */
5
6/**
7 * @param {RegExp | string } re
8 * @returns {string}
9 */
10function source(re) {
11 if (!re) return null;
12 if (typeof re === "string") return re;
13
14 return re.source;
15}
16
17/**
18 * @param {...(RegExp | string) } args
19 * @returns {string}
20 */
21function concat(...args) {
22 const joined = args.map((x) => source(x)).join("");
23 return joined;
24}
25
26/**
27 * Any of the passed expresssions may match
28 *
29 * Creates a huge this | this | that | that match
30 * @param {(RegExp | string)[] } args
31 * @returns {string}
32 */
33function either(...args) {
34 const joined = '(' + args.map((x) => source(x)).join("|") + ")";
35 return joined;
36}
37
38/*
39 Language: Apache Access Log
40 Author: Oleg Efimov <efimovov@gmail.com>
41 Description: Apache/Nginx Access Logs
42 Website: https://httpd.apache.org/docs/2.4/logs.html#accesslog
43 Audit: 2020
44 */
45
46/** @type LanguageFn */
47function accesslog(_hljs) {
48 // https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
49 const HTTP_VERBS = [
50 "GET",
51 "POST",
52 "HEAD",
53 "PUT",
54 "DELETE",
55 "CONNECT",
56 "OPTIONS",
57 "PATCH",
58 "TRACE"
59 ];
60 return {
61 name: 'Apache Access Log',
62 contains: [
63 // IP
64 {
65 className: 'number',
66 begin: /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(:\d{1,5})?\b/,
67 relevance: 5
68 },
69 // Other numbers
70 {
71 className: 'number',
72 begin: /\b\d+\b/,
73 relevance: 0
74 },
75 // Requests
76 {
77 className: 'string',
78 begin: concat(/"/, either(...HTTP_VERBS)),
79 end: /"/,
80 keywords: HTTP_VERBS,
81 illegal: /\n/,
82 relevance: 5,
83 contains: [
84 {
85 begin: /HTTP\/[12]\.\d'/,
86 relevance: 5
87 }
88 ]
89 },
90 // Dates
91 {
92 className: 'string',
93 // dates must have a certain length, this prevents matching
94 // simple array accesses a[123] and [] and other common patterns
95 // found in other languages
96 begin: /\[\d[^\]\n]{8,}\]/,
97 illegal: /\n/,
98 relevance: 1
99 },
100 {
101 className: 'string',
102 begin: /\[/,
103 end: /\]/,
104 illegal: /\n/,
105 relevance: 0
106 },
107 // User agent / relevance boost
108 {
109 className: 'string',
110 begin: /"Mozilla\/\d\.\d \(/,
111 end: /"/,
112 illegal: /\n/,
113 relevance: 3
114 },
115 // Strings
116 {
117 className: 'string',
118 begin: /"/,
119 end: /"/,
120 illegal: /\n/,
121 relevance: 0
122 }
123 ]
124 };
125}
126
127module.exports = accesslog;
Note: See TracBrowser for help on using the repository browser.