comparison third_party/highlight/languages/http.js @ 173:827c6ac504cd hg-web

Merged in default here.
author MrJuneJune <me@mrjunejune.com>
date Mon, 19 Jan 2026 18:59:10 -0800
parents 2db6253f355d
children
comparison
equal deleted inserted replaced
151:c033667da5f9 173:827c6ac504cd
1 /*! `http` grammar compiled for Highlight.js 11.11.1 */
2 (function(){
3 var hljsGrammar = (function () {
4 'use strict';
5
6 /*
7 Language: HTTP
8 Description: HTTP request and response headers with automatic body highlighting
9 Author: Ivan Sagalaev <[email protected]>
10 Category: protocols, web
11 Website: https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview
12 */
13
14 function http(hljs) {
15 const regex = hljs.regex;
16 const VERSION = 'HTTP/([32]|1\\.[01])';
17 const HEADER_NAME = /[A-Za-z][A-Za-z0-9-]*/;
18 const HEADER = {
19 className: 'attribute',
20 begin: regex.concat('^', HEADER_NAME, '(?=\\:\\s)'),
21 starts: { contains: [
22 {
23 className: "punctuation",
24 begin: /: /,
25 relevance: 0,
26 starts: {
27 end: '$',
28 relevance: 0
29 }
30 }
31 ] }
32 };
33 const HEADERS_AND_BODY = [
34 HEADER,
35 {
36 begin: '\\n\\n',
37 starts: {
38 subLanguage: [],
39 endsWithParent: true
40 }
41 }
42 ];
43
44 return {
45 name: 'HTTP',
46 aliases: [ 'https' ],
47 illegal: /\S/,
48 contains: [
49 // response
50 {
51 begin: '^(?=' + VERSION + " \\d{3})",
52 end: /$/,
53 contains: [
54 {
55 className: "meta",
56 begin: VERSION
57 },
58 {
59 className: 'number',
60 begin: '\\b\\d{3}\\b'
61 }
62 ],
63 starts: {
64 end: /\b\B/,
65 illegal: /\S/,
66 contains: HEADERS_AND_BODY
67 }
68 },
69 // request
70 {
71 begin: '(?=^[A-Z]+ (.*?) ' + VERSION + '$)',
72 end: /$/,
73 contains: [
74 {
75 className: 'string',
76 begin: ' ',
77 end: ' ',
78 excludeBegin: true,
79 excludeEnd: true
80 },
81 {
82 className: "meta",
83 begin: VERSION
84 },
85 {
86 className: 'keyword',
87 begin: '[A-Z]+'
88 }
89 ],
90 starts: {
91 end: /\b\B/,
92 illegal: /\S/,
93 contains: HEADERS_AND_BODY
94 }
95 },
96 // to allow headers to work even without a preamble
97 hljs.inherit(HEADER, { relevance: 0 })
98 ]
99 };
100 }
101
102 return http;
103
104 })();
105
106 hljs.registerLanguage('http', hljsGrammar);
107 })();