restructuredtext.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. define('vs/basic-languages/restructuredtext/restructuredtext',["require", "exports"], function (require, exports) {
  6. "use strict";
  7. Object.defineProperty(exports, "__esModule", { value: true });
  8. exports.language = exports.conf = void 0;
  9. exports.conf = {
  10. brackets: [
  11. ['{', '}'],
  12. ['[', ']'],
  13. ['(', ')']
  14. ],
  15. autoClosingPairs: [
  16. { open: '{', close: '}' },
  17. { open: '[', close: ']' },
  18. { open: '(', close: ')' },
  19. { open: '<', close: '>', notIn: ['string'] }
  20. ],
  21. surroundingPairs: [
  22. { open: '(', close: ')' },
  23. { open: '[', close: ']' },
  24. { open: '`', close: '`' }
  25. ],
  26. folding: {
  27. markers: {
  28. start: new RegExp('^\\s*<!--\\s*#?region\\b.*-->'),
  29. end: new RegExp('^\\s*<!--\\s*#?endregion\\b.*-->')
  30. }
  31. }
  32. };
  33. exports.language = {
  34. defaultToken: '',
  35. tokenPostfix: '.rst',
  36. control: /[\\`*_\[\]{}()#+\-\.!]/,
  37. escapes: /\\(?:@control)/,
  38. empty: [
  39. 'area',
  40. 'base',
  41. 'basefont',
  42. 'br',
  43. 'col',
  44. 'frame',
  45. 'hr',
  46. 'img',
  47. 'input',
  48. 'isindex',
  49. 'link',
  50. 'meta',
  51. 'param'
  52. ],
  53. alphanumerics: /[A-Za-z0-9]/,
  54. simpleRefNameWithoutBq: /(?:@alphanumerics[-_+:.]*@alphanumerics)+|(?:@alphanumerics+)/,
  55. simpleRefName: /(?:`@phrase`|@simpleRefNameWithoutBq)/,
  56. phrase: /@simpleRefNameWithoutBq(?:\s@simpleRefNameWithoutBq)*/,
  57. citationName: /[A-Za-z][A-Za-z0-9-_.]*/,
  58. blockLiteralStart: /(?:[!"#$%&'()*+,-./:;<=>?@\[\]^_`{|}~]|[\s])/,
  59. precedingChars: /(?:[ -:/'"<([{])/,
  60. followingChars: /(?:[ -.,:;!?/'")\]}>]|$)/,
  61. punctuation: /(=|-|~|`|#|"|\^|\+|\*|:|\.|'|_|\+)/,
  62. tokenizer: {
  63. root: [
  64. //sections
  65. [/^(@punctuation{3,}$){1,1}?/, 'keyword'],
  66. //line-blocks
  67. //No rules on it
  68. //bullet-lists
  69. [/^\s*([\*\-+‣•]|[a-zA-Z0-9]+\.|\([a-zA-Z0-9]+\)|[a-zA-Z0-9]+\))\s/, 'keyword'],
  70. //literal-blocks
  71. [/([ ]::)\s*$/, 'keyword', '@blankLineOfLiteralBlocks'],
  72. [/(::)\s*$/, 'keyword', '@blankLineOfLiteralBlocks'],
  73. { include: '@tables' },
  74. { include: '@explicitMarkupBlocks' },
  75. { include: '@inlineMarkup' }
  76. ],
  77. explicitMarkupBlocks: [
  78. //citations
  79. { include: '@citations' },
  80. //footnotes
  81. { include: '@footnotes' },
  82. //directives
  83. [
  84. /^(\.\.\s)(@simpleRefName)(::\s)(.*)$/,
  85. [{ token: '', next: 'subsequentLines' }, 'keyword', '', '']
  86. ],
  87. //hyperlink-targets
  88. [
  89. /^(\.\.)(\s+)(_)(@simpleRefName)(:)(\s+)(.*)/,
  90. [{ token: '', next: 'hyperlinks' }, '', '', 'string.link', '', '', 'string.link']
  91. ],
  92. //anonymous-hyperlinks
  93. [
  94. /^((?:(?:\.\.)(?:\s+))?)(__)(:)(\s+)(.*)/,
  95. [{ token: '', next: 'subsequentLines' }, '', '', '', 'string.link']
  96. ],
  97. [/^(__\s+)(.+)/, ['', 'string.link']],
  98. //substitution-definitions
  99. [
  100. /^(\.\.)( \|)([^| ]+[^|]*[^| ]*)(\| )(@simpleRefName)(:: .*)/,
  101. [{ token: '', next: 'subsequentLines' }, '', 'string.link', '', 'keyword', ''],
  102. '@rawBlocks'
  103. ],
  104. [/(\|)([^| ]+[^|]*[^| ]*)(\|_{0,2})/, ['', 'string.link', '']],
  105. //comments
  106. [/^(\.\.)([ ].*)$/, [{ token: '', next: '@comments' }, 'comment']]
  107. ],
  108. inlineMarkup: [
  109. { include: '@citationsReference' },
  110. { include: '@footnotesReference' },
  111. //hyperlink-references
  112. [/(@simpleRefName)(_{1,2})/, ['string.link', '']],
  113. //embedded-uris-and-aliases
  114. [/(`)([^<`]+\s+)(<)(.*)(>)(`)(_)/, ['', 'string.link', '', 'string.link', '', '', '']],
  115. //emphasis
  116. [/\*\*([^\\*]|\*(?!\*))+\*\*/, 'strong'],
  117. [/\*[^*]+\*/, 'emphasis'],
  118. //inline-literals
  119. [/(``)((?:[^`]|\`(?!`))+)(``)/, ['', 'keyword', '']],
  120. [/(__\s+)(.+)/, ['', 'keyword']],
  121. //interpreted-text
  122. [/(:)((?:@simpleRefNameWithoutBq)?)(:`)([^`]+)(`)/, ['', 'keyword', '', '', '']],
  123. [/(`)([^`]+)(`:)((?:@simpleRefNameWithoutBq)?)(:)/, ['', '', '', 'keyword', '']],
  124. [/(`)([^`]+)(`)/, ''],
  125. //inline-internal-targets
  126. [/(_`)(@phrase)(`)/, ['', 'string.link', '']]
  127. ],
  128. citations: [
  129. [
  130. /^(\.\.\s+\[)((?:@citationName))(\]\s+)(.*)/,
  131. [{ token: '', next: '@subsequentLines' }, 'string.link', '', '']
  132. ]
  133. ],
  134. citationsReference: [[/(\[)(@citationName)(\]_)/, ['', 'string.link', '']]],
  135. footnotes: [
  136. [
  137. /^(\.\.\s+\[)((?:[0-9]+))(\]\s+.*)/,
  138. [{ token: '', next: '@subsequentLines' }, 'string.link', '']
  139. ],
  140. [
  141. /^(\.\.\s+\[)((?:#@simpleRefName?))(\]\s+)(.*)/,
  142. [{ token: '', next: '@subsequentLines' }, 'string.link', '', '']
  143. ],
  144. [
  145. /^(\.\.\s+\[)((?:\*))(\]\s+)(.*)/,
  146. [{ token: '', next: '@subsequentLines' }, 'string.link', '', '']
  147. ]
  148. ],
  149. footnotesReference: [
  150. [/(\[)([0-9]+)(\])(_)/, ['', 'string.link', '', '']],
  151. [/(\[)(#@simpleRefName?)(\])(_)/, ['', 'string.link', '', '']],
  152. [/(\[)(\*)(\])(_)/, ['', 'string.link', '', '']]
  153. ],
  154. blankLineOfLiteralBlocks: [
  155. [/^$/, '', '@subsequentLinesOfLiteralBlocks'],
  156. [/^.*$/, '', '@pop']
  157. ],
  158. subsequentLinesOfLiteralBlocks: [
  159. [/(@blockLiteralStart+)(.*)/, ['keyword', '']],
  160. [/^(?!blockLiteralStart)/, '', '@popall']
  161. ],
  162. subsequentLines: [
  163. [/^[\s]+.*/, ''],
  164. [/^(?!\s)/, '', '@pop']
  165. ],
  166. hyperlinks: [
  167. [/^[\s]+.*/, 'string.link'],
  168. [/^(?!\s)/, '', '@pop']
  169. ],
  170. comments: [
  171. [/^[\s]+.*/, 'comment'],
  172. [/^(?!\s)/, '', '@pop']
  173. ],
  174. tables: [
  175. [/\+-[+-]+/, 'keyword'],
  176. [/\+=[+=]+/, 'keyword']
  177. ]
  178. }
  179. };
  180. });