nginx.js (2547B)
1 /* 2 Language: Nginx config 3 Author: Peter Leonov <gojpeg@yandex.ru> 4 Contributors: Ivan Sagalaev <maniac@softwaremaniacs.org> 5 Category: common, config 6 Website: https://www.nginx.com 7 */ 8 9 function nginx(hljs) { 10 var VAR = { 11 className: 'variable', 12 variants: [ 13 {begin: /\$\d+/}, 14 {begin: /\$\{/, end: /}/}, 15 {begin: '[\\$\\@]' + hljs.UNDERSCORE_IDENT_RE} 16 ] 17 }; 18 var DEFAULT = { 19 endsWithParent: true, 20 keywords: { 21 $pattern: '[a-z/_]+', 22 literal: 23 'on off yes no true false none blocked debug info notice warn error crit ' + 24 'select break last permanent redirect kqueue rtsig epoll poll /dev/poll' 25 }, 26 relevance: 0, 27 illegal: '=>', 28 contains: [ 29 hljs.HASH_COMMENT_MODE, 30 { 31 className: 'string', 32 contains: [hljs.BACKSLASH_ESCAPE, VAR], 33 variants: [ 34 {begin: /"/, end: /"/}, 35 {begin: /'/, end: /'/} 36 ] 37 }, 38 // this swallows entire URLs to avoid detecting numbers within 39 { 40 begin: '([a-z]+):/', end: '\\s', endsWithParent: true, excludeEnd: true, 41 contains: [VAR] 42 }, 43 { 44 className: 'regexp', 45 contains: [hljs.BACKSLASH_ESCAPE, VAR], 46 variants: [ 47 {begin: "\\s\\^", end: "\\s|{|;", returnEnd: true}, 48 // regexp locations (~, ~*) 49 {begin: "~\\*?\\s+", end: "\\s|{|;", returnEnd: true}, 50 // *.example.com 51 {begin: "\\*(\\.[a-z\\-]+)+"}, 52 // sub.example.* 53 {begin: "([a-z\\-]+\\.)+\\*"} 54 ] 55 }, 56 // IP 57 { 58 className: 'number', 59 begin: '\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}(:\\d{1,5})?\\b' 60 }, 61 // units 62 { 63 className: 'number', 64 begin: '\\b\\d+[kKmMgGdshdwy]*\\b', 65 relevance: 0 66 }, 67 VAR 68 ] 69 }; 70 71 return { 72 name: 'Nginx config', 73 aliases: ['nginxconf'], 74 contains: [ 75 hljs.HASH_COMMENT_MODE, 76 { 77 begin: hljs.UNDERSCORE_IDENT_RE + '\\s+{', returnBegin: true, 78 end: '{', 79 contains: [ 80 { 81 className: 'section', 82 begin: hljs.UNDERSCORE_IDENT_RE 83 } 84 ], 85 relevance: 0 86 }, 87 { 88 begin: hljs.UNDERSCORE_IDENT_RE + '\\s', end: ';|{', returnBegin: true, 89 contains: [ 90 { 91 className: 'attribute', 92 begin: hljs.UNDERSCORE_IDENT_RE, 93 starts: DEFAULT 94 } 95 ], 96 relevance: 0 97 } 98 ], 99 illegal: '[^\\s\\}]' 100 }; 101 } 102 103 module.exports = nginx;