prism-http.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. Prism.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. // Create a mapping of Content-Type headers to language definitions
  22. var httpLanguages = {
  23. 'application/json': Prism.languages.javascript,
  24. 'application/xml': Prism.languages.markup,
  25. 'text/xml': Prism.languages.markup,
  26. 'text/html': Prism.languages.markup
  27. };
  28. // Insert each content type parser that has its associated language
  29. // currently loaded.
  30. for (var contentType in httpLanguages) {
  31. if (httpLanguages[contentType]) {
  32. var options = {};
  33. options[contentType] = {
  34. pattern: new RegExp('(content-type:\\s*' + contentType + '[\\w\\W]*?)\\n\\n[\\w\\W]*', 'i'),
  35. lookbehind: true,
  36. inside: {
  37. rest: httpLanguages[contentType]
  38. }
  39. };
  40. Prism.languages.insertBefore('http', 'keyword', options);
  41. }
  42. }