-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HTTP: Fix indentation + Add multiline flag for more flexibility + Fix…
… response status + Handle \r\n and \r
- Loading branch information
Showing
2 changed files
with
40 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,50 @@ | ||
Prism.languages.http = { | ||
'request-line': { | ||
pattern: /^(POST|GET|PUT|DELETE|OPTIONS|PATCH|TRACE|CONNECT)\b\shttps?:\/\/\S+\sHTTP\/[0-9.]+/, | ||
inside: { | ||
// HTTP Verb | ||
property: /^\b(POST|GET|PUT|DELETE|OPTIONS|PATCH|TRACE|CONNECT)\b/, | ||
// Path or query argument | ||
'attr-name': /:\w+/ | ||
} | ||
}, | ||
'response-status': { | ||
pattern: /^HTTP\/1.[01] [0-9]+.*/, | ||
inside: { | ||
// Status, e.g. 200 OK | ||
property: /[0-9]+[A-Z\s-]+$/i | ||
} | ||
}, | ||
// HTTP header name | ||
keyword: /^[\w-]+:(?=.+)/m | ||
'request-line': { | ||
pattern: /^(POST|GET|PUT|DELETE|OPTIONS|PATCH|TRACE|CONNECT)\b\shttps?:\/\/\S+\sHTTP\/[0-9.]+/m, | ||
inside: { | ||
// HTTP Verb | ||
property: /^(POST|GET|PUT|DELETE|OPTIONS|PATCH|TRACE|CONNECT)\b/, | ||
// Path or query argument | ||
'attr-name': /:\w+/ | ||
} | ||
}, | ||
'response-status': { | ||
pattern: /^HTTP\/1.[01] [0-9]+.*/m, | ||
inside: { | ||
// Status, e.g. 200 OK | ||
property: { | ||
pattern: /(^HTTP\/1.[01] )[0-9]+.*/i, | ||
lookbehind: true | ||
} | ||
} | ||
}, | ||
// HTTP header name | ||
'header-name': { | ||
pattern: /^[\w-]+:(?=.)/m, | ||
alias: 'keyword' | ||
} | ||
}; | ||
|
||
// Create a mapping of Content-Type headers to language definitions | ||
var httpLanguages = { | ||
'application/json': Prism.languages.javascript, | ||
'application/xml': Prism.languages.markup, | ||
'text/xml': Prism.languages.markup, | ||
'text/html': Prism.languages.markup | ||
'application/json': Prism.languages.javascript, | ||
'application/xml': Prism.languages.markup, | ||
'text/xml': Prism.languages.markup, | ||
'text/html': Prism.languages.markup | ||
}; | ||
|
||
// Insert each content type parser that has its associated language | ||
// currently loaded. | ||
for (var contentType in httpLanguages) { | ||
if (httpLanguages[contentType]) { | ||
var options = {}; | ||
options[contentType] = { | ||
pattern: new RegExp('(content-type:\\s*' + contentType + '[\\w\\W]*?)\\n\\n[\\w\\W]*', 'i'), | ||
lookbehind: true, | ||
inside: { | ||
rest: httpLanguages[contentType] | ||
} | ||
}; | ||
Prism.languages.insertBefore('http', 'keyword', options); | ||
} | ||
if (httpLanguages[contentType]) { | ||
var options = {}; | ||
options[contentType] = { | ||
pattern: new RegExp('(content-type:\\s*' + contentType + '[\\w\\W]*?)(?:\\r?\\n|\\r){2}[\\w\\W]*', 'i'), | ||
lookbehind: true, | ||
inside: { | ||
rest: httpLanguages[contentType] | ||
} | ||
}; | ||
Prism.languages.insertBefore('http', 'header-name', options); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.