main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
2.4 KB
|
Rev | Line | |
---|
[d24f17c] | 1 | /**
|
---|
| 2 | * @param {string} value
|
---|
| 3 | * @returns {RegExp}
|
---|
| 4 | * */
|
---|
| 5 |
|
---|
| 6 | /**
|
---|
| 7 | * @param {RegExp | string } re
|
---|
| 8 | * @returns {string}
|
---|
| 9 | */
|
---|
| 10 | function 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 | */
|
---|
| 21 | function concat(...args) {
|
---|
| 22 | const joined = args.map((x) => source(x)).join("");
|
---|
| 23 | return joined;
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | /*
|
---|
| 27 | Language: HTTP
|
---|
| 28 | Description: HTTP request and response headers with automatic body highlighting
|
---|
| 29 | Author: Ivan Sagalaev <maniac@softwaremaniacs.org>
|
---|
| 30 | Category: common, protocols
|
---|
| 31 | Website: https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview
|
---|
| 32 | */
|
---|
| 33 |
|
---|
| 34 | function http(hljs) {
|
---|
| 35 | const VERSION = 'HTTP/(2|1\\.[01])';
|
---|
| 36 | const HEADER_NAME = /[A-Za-z][A-Za-z0-9-]*/;
|
---|
| 37 | const HEADER = {
|
---|
| 38 | className: 'attribute',
|
---|
| 39 | begin: concat('^', HEADER_NAME, '(?=\\:\\s)'),
|
---|
| 40 | starts: {
|
---|
| 41 | contains: [
|
---|
| 42 | {
|
---|
| 43 | className: "punctuation",
|
---|
| 44 | begin: /: /,
|
---|
| 45 | relevance: 0,
|
---|
| 46 | starts: {
|
---|
| 47 | end: '$',
|
---|
| 48 | relevance: 0
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 | ]
|
---|
| 52 | }
|
---|
| 53 | };
|
---|
| 54 | const HEADERS_AND_BODY = [
|
---|
| 55 | HEADER,
|
---|
| 56 | {
|
---|
| 57 | begin: '\\n\\n',
|
---|
| 58 | starts: { subLanguage: [], endsWithParent: true }
|
---|
| 59 | }
|
---|
| 60 | ];
|
---|
| 61 |
|
---|
| 62 | return {
|
---|
| 63 | name: 'HTTP',
|
---|
| 64 | aliases: ['https'],
|
---|
| 65 | illegal: /\S/,
|
---|
| 66 | contains: [
|
---|
| 67 | // response
|
---|
| 68 | {
|
---|
| 69 | begin: '^(?=' + VERSION + " \\d{3})",
|
---|
| 70 | end: /$/,
|
---|
| 71 | contains: [
|
---|
| 72 | {
|
---|
| 73 | className: "meta",
|
---|
| 74 | begin: VERSION
|
---|
| 75 | },
|
---|
| 76 | {
|
---|
| 77 | className: 'number', begin: '\\b\\d{3}\\b'
|
---|
| 78 | }
|
---|
| 79 | ],
|
---|
| 80 | starts: {
|
---|
| 81 | end: /\b\B/,
|
---|
| 82 | illegal: /\S/,
|
---|
| 83 | contains: HEADERS_AND_BODY
|
---|
| 84 | }
|
---|
| 85 | },
|
---|
| 86 | // request
|
---|
| 87 | {
|
---|
| 88 | begin: '(?=^[A-Z]+ (.*?) ' + VERSION + '$)',
|
---|
| 89 | end: /$/,
|
---|
| 90 | contains: [
|
---|
| 91 | {
|
---|
| 92 | className: 'string',
|
---|
| 93 | begin: ' ',
|
---|
| 94 | end: ' ',
|
---|
| 95 | excludeBegin: true,
|
---|
| 96 | excludeEnd: true
|
---|
| 97 | },
|
---|
| 98 | {
|
---|
| 99 | className: "meta",
|
---|
| 100 | begin: VERSION
|
---|
| 101 | },
|
---|
| 102 | {
|
---|
| 103 | className: 'keyword',
|
---|
| 104 | begin: '[A-Z]+'
|
---|
| 105 | }
|
---|
| 106 | ],
|
---|
| 107 | starts: {
|
---|
| 108 | end: /\b\B/,
|
---|
| 109 | illegal: /\S/,
|
---|
| 110 | contains: HEADERS_AND_BODY
|
---|
| 111 | }
|
---|
| 112 | },
|
---|
| 113 | // to allow headers to work even without a preamble
|
---|
| 114 | hljs.inherit(HEADER, {
|
---|
| 115 | relevance: 0
|
---|
| 116 | })
|
---|
| 117 | ]
|
---|
| 118 | };
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | module.exports = http;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.