comparison third_party/highlight/es/languages/http.js @ 157:2db6253f355d

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