prism-rest.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. Prism.languages.rest = {
  2. 'table': [
  3. {
  4. pattern: /(\s*)(?:\+[=-]+)+\+(?:\r?\n|\r)(?:\1(?:[+|].+)+[+|](?:\r?\n|\r))+\1(?:\+[=-]+)+\+/,
  5. lookbehind: true,
  6. inside: {
  7. 'punctuation': /\||(?:\+[=-]+)+\+/
  8. }
  9. },
  10. {
  11. pattern: /(\s*)(?:=+ +)+=+((?:\r?\n|\r)\1.+)+(?:\r?\n|\r)\1(?:=+ +)+=+(?=(?:\r?\n|\r){2}|\s*$)/,
  12. lookbehind: true,
  13. inside: {
  14. 'punctuation': /[=-]+/
  15. }
  16. }
  17. ],
  18. // Directive-like patterns
  19. 'substitution-def': {
  20. pattern: /(^\s*\.\. )\|(?:[^|\s]|[^|\s][^|]*[^|\s])\| [^:]+::/m,
  21. lookbehind: true,
  22. inside: {
  23. 'substitution': {
  24. pattern: /^\|(?:[^|\s]|[^|\s][^|]*[^|\s])\|/,
  25. alias: 'attr-value',
  26. inside: {
  27. 'punctuation': /^\||\|$/
  28. }
  29. },
  30. 'directive': {
  31. pattern: /( )[^:]+::/,
  32. lookbehind: true,
  33. alias: 'function',
  34. inside: {
  35. 'punctuation': /::$/
  36. }
  37. }
  38. }
  39. },
  40. 'link-target': [
  41. {
  42. pattern: /(^\s*\.\. )\[[^\]]+\]/m,
  43. lookbehind: true,
  44. alias: 'string',
  45. inside: {
  46. 'punctuation': /^\[|\]$/
  47. }
  48. },
  49. {
  50. pattern: /(^\s*\.\. )_(?:`[^`]+`|(?:\\:|[^:])+):/m,
  51. lookbehind: true,
  52. alias: 'string',
  53. inside: {
  54. 'punctuation': /^_|:$/
  55. }
  56. }
  57. ],
  58. 'directive': {
  59. pattern: /(^\s*\.\. )[^:]+::/m,
  60. lookbehind: true,
  61. alias: 'function',
  62. inside: {
  63. 'punctuation': /::$/
  64. }
  65. },
  66. 'comment': {
  67. pattern: /(^\s*\.\.\s).*(?:(?:\r?\n|\r).*)*?(?=(?:\r?\n|\r){2}|$)/m,
  68. lookbehind: true
  69. },
  70. 'title': [
  71. // Overlined and underlined
  72. {
  73. pattern: /^([!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~]{2,})(?:\r?\n|\r).+(?:\r?\n|\r)\1$/m,
  74. inside: {
  75. 'punctuation': /^[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~]+|[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~]+$/,
  76. 'important': /.+/
  77. }
  78. },
  79. // Underlined only
  80. {
  81. pattern: /(^|(?:\r?\n|\r){2}).+(?:\r?\n|\r)[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~]{2,}(?=\r?\n|\r|$)/,
  82. lookbehind: true,
  83. inside: {
  84. 'punctuation': /[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~]+$/,
  85. 'important': /.+/
  86. }
  87. }
  88. ],
  89. 'hr': {
  90. pattern: /((?:\r?\n|\r){2})[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~]{4,}(?=(?:\r?\n|\r){2})/,
  91. lookbehind: true,
  92. alias: 'punctuation'
  93. },
  94. 'list-bullet': {
  95. pattern: /(^\s*)(?:[*+\-•‣⁃]|\(?(?:\d+|[a-z]|[ivxdclm]+)\)|(?:\d+|[a-z]|[ivxdclm]+)\.)(?= )/im,
  96. lookbehind: true,
  97. alias: 'punctuation'
  98. },
  99. 'field': {
  100. pattern: /(^\s*):[^:]+:(?= )/m,
  101. lookbehind: true,
  102. alias: 'attr-name'
  103. },
  104. 'command-line-option': {
  105. pattern: /(^\s*)(?:[+-][a-z\d]|(?:\-\-|\/)[a-z\d-]+)(?:[ =](?:[a-z][a-z\d_-]*|<[^<>]+>))?(?:, (?:[+-][a-z\d]|(?:\-\-|\/)[a-z\d-]+)(?:[ =](?:[a-z][a-z\d_-]*|<[^<>]+>))?)*(?=(?:\r?\n|\r)? {2,}[\S])/im,
  106. lookbehind: true,
  107. alias: 'symbol'
  108. },
  109. 'literal-block': {
  110. pattern: /::(?:\r?\n|\r){2}([ \t]+).+(?:(?:\r?\n|\r)\1.+)*/,
  111. inside: {
  112. 'literal-block-punctuation': {
  113. pattern: /^::/,
  114. alias: 'punctuation'
  115. }
  116. }
  117. },
  118. 'quoted-literal-block': {
  119. pattern: /::(?:\r?\n|\r){2}([!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~]).*(?:(?:\r?\n|\r)\1.*)*/,
  120. inside: {
  121. 'literal-block-punctuation': {
  122. pattern: /^(?:::|[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~])/m,
  123. alias: 'punctuation'
  124. }
  125. }
  126. },
  127. 'doctest-block': {
  128. pattern: /(^\s*)>>> .+(?:(?:\r?\n|\r).+)*/m,
  129. lookbehind: true,
  130. inside: {
  131. 'punctuation': /^>>>/
  132. }
  133. },
  134. 'inline': [
  135. {
  136. pattern: /(^|[\s\-:\/'"<(\[{])(?::[^:]+:`.*?`|`.*?`:[^:]+:|(\*\*?|``?|\|)(?!\s).*?[^\s]\2(?=[\s\-.,:;!?\\\/'")\]}]|$))/m,
  137. lookbehind: true,
  138. inside: {
  139. 'bold': {
  140. pattern: /(^\*\*).+(?=\*\*$)/,
  141. lookbehind: true
  142. },
  143. 'italic': {
  144. pattern: /(^\*).+(?=\*$)/,
  145. lookbehind: true
  146. },
  147. 'inline-literal': {
  148. pattern: /(^``).+(?=``$)/,
  149. lookbehind: true,
  150. alias: 'symbol'
  151. },
  152. 'role': {
  153. pattern: /^:[^:]+:|:[^:]+:$/,
  154. alias: 'function',
  155. inside: {
  156. 'punctuation': /^:|:$/
  157. }
  158. },
  159. 'interpreted-text': {
  160. pattern: /(^`).+(?=`$)/,
  161. lookbehind: true,
  162. alias: 'attr-value'
  163. },
  164. 'substitution': {
  165. pattern: /(^\|).+(?=\|$)/,
  166. lookbehind: true,
  167. alias: 'attr-value'
  168. },
  169. 'punctuation': /\*\*?|``?|\|/
  170. }
  171. }
  172. ],
  173. 'link': [
  174. {
  175. pattern: /\[[^\]]+\]_(?=[\s\-.,:;!?\\\/'")\]}]|$)/,
  176. alias: 'string',
  177. inside: {
  178. 'punctuation': /^\[|\]_$/
  179. }
  180. },
  181. {
  182. pattern: /(?:\b[a-z\d](?:[_.:+]?[a-z\d]+)?_?_|`[^`]+`_?_|_`[^`]+`)(?=[\s\-.,:;!?\\\/'")\]}]|$)/i,
  183. alias: 'string',
  184. inside: {
  185. 'punctuation': /^_?`|`?_?_$/
  186. }
  187. }
  188. ],
  189. // Line block start,
  190. // quote attribution,
  191. // explicit markup start,
  192. // and anonymous hyperlink target shortcut (__)
  193. 'punctuation': {
  194. pattern: /(^\s*)(?:\|(?= |$)|(?:---?|—|\.\.|__)(?= )|\.\.$)/m,
  195. lookbehind: true
  196. }
  197. };