Skip to content

Commit

Permalink
HTTP: Fix indentation + Add multiline flag for more flexibility + Fix…
Browse files Browse the repository at this point in the history
… response status + Handle \r\n and \r
  • Loading branch information
Golmote committed Aug 23, 2015
1 parent 1cc8d8e commit aaa90f1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 34 deletions.
72 changes: 39 additions & 33 deletions components/prism-http.js
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);
}
}
2 changes: 1 addition & 1 deletion components/prism-http.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aaa90f1

Please sign in to comment.