restructuredtext.js 6.3 KB

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