]> luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/nginx.js
Initial commit.
[flow-web.git] / static / highlight / languages / nginx.js
1 /*! `nginx` grammar compiled for Highlight.js 11.11.1 */
2 (function(){
3 var hljsGrammar = (function () {
4 'use strict';
5
6 /*
7 Language: Nginx config
8 Author: Peter Leonov <gojpeg@yandex.ru>
9 Contributors: Ivan Sagalaev <maniac@softwaremaniacs.org>
10 Category: config, web
11 Website: https://www.nginx.com
12 */
13
14 /** @type LanguageFn */
15 function nginx(hljs) {
16 const regex = hljs.regex;
17 const VAR = {
18 className: 'variable',
19 variants: [
20 { begin: /\$\d+/ },
21 { begin: /\$\{\w+\}/ },
22 { begin: regex.concat(/[$@]/, hljs.UNDERSCORE_IDENT_RE) }
23 ]
24 };
25 const LITERALS = [
26 "on",
27 "off",
28 "yes",
29 "no",
30 "true",
31 "false",
32 "none",
33 "blocked",
34 "debug",
35 "info",
36 "notice",
37 "warn",
38 "error",
39 "crit",
40 "select",
41 "break",
42 "last",
43 "permanent",
44 "redirect",
45 "kqueue",
46 "rtsig",
47 "epoll",
48 "poll",
49 "/dev/poll"
50 ];
51 const DEFAULT = {
52 endsWithParent: true,
53 keywords: {
54 $pattern: /[a-z_]{2,}|\/dev\/poll/,
55 literal: LITERALS
56 },
57 relevance: 0,
58 illegal: '=>',
59 contains: [
60 hljs.HASH_COMMENT_MODE,
61 {
62 className: 'string',
63 contains: [
64 hljs.BACKSLASH_ESCAPE,
65 VAR
66 ],
67 variants: [
68 {
69 begin: /"/,
70 end: /"/
71 },
72 {
73 begin: /'/,
74 end: /'/
75 }
76 ]
77 },
78 // this swallows entire URLs to avoid detecting numbers within
79 {
80 begin: '([a-z]+):/',
81 end: '\\s',
82 endsWithParent: true,
83 excludeEnd: true,
84 contains: [ VAR ]
85 },
86 {
87 className: 'regexp',
88 contains: [
89 hljs.BACKSLASH_ESCAPE,
90 VAR
91 ],
92 variants: [
93 {
94 begin: "\\s\\^",
95 end: "\\s|\\{|;",
96 returnEnd: true
97 },
98 // regexp locations (~, ~*)
99 {
100 begin: "~\\*?\\s+",
101 end: "\\s|\\{|;",
102 returnEnd: true
103 },
104 // *.example.com
105 { begin: "\\*(\\.[a-z\\-]+)+" },
106 // sub.example.*
107 { begin: "([a-z\\-]+\\.)+\\*" }
108 ]
109 },
110 // IP
111 {
112 className: 'number',
113 begin: '\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}(:\\d{1,5})?\\b'
114 },
115 // units
116 {
117 className: 'number',
118 begin: '\\b\\d+[kKmMgGdshdwy]?\\b',
119 relevance: 0
120 },
121 VAR
122 ]
123 };
124
125 return {
126 name: 'Nginx config',
127 aliases: [ 'nginxconf' ],
128 contains: [
129 hljs.HASH_COMMENT_MODE,
130 {
131 beginKeywords: "upstream location",
132 end: /;|\{/,
133 contains: DEFAULT.contains,
134 keywords: { section: "upstream location" }
135 },
136 {
137 className: 'section',
138 begin: regex.concat(hljs.UNDERSCORE_IDENT_RE + regex.lookahead(/\s+\{/)),
139 relevance: 0
140 },
141 {
142 begin: regex.lookahead(hljs.UNDERSCORE_IDENT_RE + '\\s'),
143 end: ';|\\{',
144 contains: [
145 {
146 className: 'attribute',
147 begin: hljs.UNDERSCORE_IDENT_RE,
148 starts: DEFAULT
149 }
150 ],
151 relevance: 0
152 }
153 ],
154 illegal: '[^\\s\\}\\{]'
155 };
156 }
157
158 return nginx;
159
160 })();
161
162 hljs.registerLanguage('nginx', hljsGrammar);
163 })();