UNPKG

1.41 kBJavaScriptView Raw
1Prism.languages.http = {
2 'request-line': {
3 pattern: /^(POST|GET|PUT|DELETE|OPTIONS|PATCH|TRACE|CONNECT)\b\shttps?:\/\/\S+\sHTTP\/[0-9.]+/,
4 inside: {
5 // HTTP Verb
6 property: /^\b(POST|GET|PUT|DELETE|OPTIONS|PATCH|TRACE|CONNECT)\b/,
7 // Path or query argument
8 'attr-name': /:\w+/
9 }
10 },
11 'response-status': {
12 pattern: /^HTTP\/1.[01] [0-9]+.*/,
13 inside: {
14 // Status, e.g. 200 OK
15 property: /[0-9]+[A-Z\s-]+$/i
16 }
17 },
18 // HTTP header name
19 keyword: /^[\w-]+:(?=.+)/m
20};
21
22// Create a mapping of Content-Type headers to language definitions
23var httpLanguages = {
24 'application/json': Prism.languages.javascript,
25 'application/xml': Prism.languages.markup,
26 'text/xml': Prism.languages.markup,
27 'text/html': Prism.languages.markup
28};
29
30// Insert each content type parser that has its associated language
31// currently loaded.
32for (var contentType in httpLanguages) {
33 if (httpLanguages[contentType]) {
34 var options = {};
35 options[contentType] = {
36 pattern: new RegExp('(content-type:\\s*' + contentType + '[\\w\\W]*?)\\n\\n[\\w\\W]*', 'i'),
37 lookbehind: true,
38 inside: {
39 rest: httpLanguages[contentType]
40 }
41 };
42 Prism.languages.insertBefore('http', 'keyword', options);
43 }
44}