restructuredtext.js 6.6 KB

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