prism-rest.js 4.7 KB

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