prism-uri.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // https://tools.ietf.org/html/rfc3986#appendix-A
  2. Prism.languages.uri = {
  3. 'scheme': {
  4. pattern: /^[a-z][a-z0-9+.-]*:/im,
  5. greedy: true,
  6. inside: {
  7. 'scheme-delimiter': /:$/
  8. }
  9. },
  10. 'fragment': {
  11. pattern: /#[\w\-.~!$&'()*+,;=%:@/?]*/,
  12. inside: {
  13. 'fragment-delimiter': /^#/
  14. }
  15. },
  16. 'query': {
  17. pattern: /\?[\w\-.~!$&'()*+,;=%:@/?]*/,
  18. inside: {
  19. 'query-delimiter': {
  20. pattern: /^\?/,
  21. greedy: true
  22. },
  23. 'pair-delimiter': /[&;]/,
  24. 'pair': {
  25. pattern: /^[^=][\s\S]*/,
  26. inside: {
  27. 'key': /^[^=]+/,
  28. 'value': {
  29. pattern: /(^=)[\s\S]+/,
  30. lookbehind: true
  31. }
  32. }
  33. }
  34. }
  35. },
  36. 'authority': {
  37. pattern: RegExp(
  38. /^\/\//.source
  39. // [ userinfo "@" ]
  40. + /(?:[\w\-.~!$&'()*+,;=%:]*@)?/.source
  41. // host
  42. + (
  43. '(?:'
  44. // IP-literal
  45. + /\[(?:[0-9a-fA-F:.]{2,48}|v[0-9a-fA-F]+\.[\w\-.~!$&'()*+,;=]+)\]/.source
  46. + '|'
  47. // IPv4address or registered name
  48. + /[\w\-.~!$&'()*+,;=%]*/.source
  49. + ')'
  50. )
  51. // [ ":" port ]
  52. + /(?::\d*)?/.source,
  53. 'm'
  54. ),
  55. inside: {
  56. 'authority-delimiter': /^\/\//,
  57. 'user-info-segment': {
  58. pattern: /^[\w\-.~!$&'()*+,;=%:]*@/,
  59. inside: {
  60. 'user-info-delimiter': /@$/,
  61. 'user-info': /^[\w\-.~!$&'()*+,;=%:]+/
  62. }
  63. },
  64. 'port-segment': {
  65. pattern: /:\d*$/,
  66. inside: {
  67. 'port-delimiter': /^:/,
  68. 'port': /^\d+/
  69. }
  70. },
  71. 'host': {
  72. pattern: /[\s\S]+/,
  73. inside: {
  74. 'ip-literal': {
  75. pattern: /^\[[\s\S]+\]$/,
  76. inside: {
  77. 'ip-literal-delimiter': /^\[|\]$/,
  78. 'ipv-future': /^v[\s\S]+/,
  79. 'ipv6-address': /^[\s\S]+/
  80. }
  81. },
  82. 'ipv4-address': /^(?:(?:[03-9]\d?|[12]\d{0,2})\.){3}(?:[03-9]\d?|[12]\d{0,2})$/
  83. }
  84. }
  85. }
  86. },
  87. 'path': {
  88. pattern: /^[\w\-.~!$&'()*+,;=%:@/]+/m,
  89. inside: {
  90. 'path-separator': /\//
  91. }
  92. }
  93. };
  94. Prism.languages.url = Prism.languages.uri;