restructuredtext.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*!-----------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Version: 0.31.1(337587859b1c171314b40503171188b6cea6a32a)
  4. * Released under the MIT license
  5. * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
  6. *-----------------------------------------------------------------------------*/
  7. // src/basic-languages/restructuredtext/restructuredtext.ts
  8. var 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. var language = {
  33. defaultToken: "",
  34. tokenPostfix: ".rst",
  35. control: /[\\`*_\[\]{}()#+\-\.!]/,
  36. escapes: /\\(?:@control)/,
  37. empty: [
  38. "area",
  39. "base",
  40. "basefont",
  41. "br",
  42. "col",
  43. "frame",
  44. "hr",
  45. "img",
  46. "input",
  47. "isindex",
  48. "link",
  49. "meta",
  50. "param"
  51. ],
  52. alphanumerics: /[A-Za-z0-9]/,
  53. simpleRefNameWithoutBq: /(?:@alphanumerics[-_+:.]*@alphanumerics)+|(?:@alphanumerics+)/,
  54. simpleRefName: /(?:`@phrase`|@simpleRefNameWithoutBq)/,
  55. phrase: /@simpleRefNameWithoutBq(?:\s@simpleRefNameWithoutBq)*/,
  56. citationName: /[A-Za-z][A-Za-z0-9-_.]*/,
  57. blockLiteralStart: /(?:[!"#$%&'()*+,-./:;<=>?@\[\]^_`{|}~]|[\s])/,
  58. precedingChars: /(?:[ -:/'"<([{])/,
  59. followingChars: /(?:[ -.,:;!?/'")\]}>]|$)/,
  60. punctuation: /(=|-|~|`|#|"|\^|\+|\*|:|\.|'|_|\+)/,
  61. tokenizer: {
  62. root: [
  63. [/^(@punctuation{3,}$){1,1}?/, "keyword"],
  64. [/^\s*([\*\-+‣•]|[a-zA-Z0-9]+\.|\([a-zA-Z0-9]+\)|[a-zA-Z0-9]+\))\s/, "keyword"],
  65. [/([ ]::)\s*$/, "keyword", "@blankLineOfLiteralBlocks"],
  66. [/(::)\s*$/, "keyword", "@blankLineOfLiteralBlocks"],
  67. { include: "@tables" },
  68. { include: "@explicitMarkupBlocks" },
  69. { include: "@inlineMarkup" }
  70. ],
  71. explicitMarkupBlocks: [
  72. { include: "@citations" },
  73. { include: "@footnotes" },
  74. [
  75. /^(\.\.\s)(@simpleRefName)(::\s)(.*)$/,
  76. [{ token: "", next: "subsequentLines" }, "keyword", "", ""]
  77. ],
  78. [
  79. /^(\.\.)(\s+)(_)(@simpleRefName)(:)(\s+)(.*)/,
  80. [{ token: "", next: "hyperlinks" }, "", "", "string.link", "", "", "string.link"]
  81. ],
  82. [
  83. /^((?:(?:\.\.)(?:\s+))?)(__)(:)(\s+)(.*)/,
  84. [{ token: "", next: "subsequentLines" }, "", "", "", "string.link"]
  85. ],
  86. [/^(__\s+)(.+)/, ["", "string.link"]],
  87. [
  88. /^(\.\.)( \|)([^| ]+[^|]*[^| ]*)(\| )(@simpleRefName)(:: .*)/,
  89. [{ token: "", next: "subsequentLines" }, "", "string.link", "", "keyword", ""],
  90. "@rawBlocks"
  91. ],
  92. [/(\|)([^| ]+[^|]*[^| ]*)(\|_{0,2})/, ["", "string.link", ""]],
  93. [/^(\.\.)([ ].*)$/, [{ token: "", next: "@comments" }, "comment"]]
  94. ],
  95. inlineMarkup: [
  96. { include: "@citationsReference" },
  97. { include: "@footnotesReference" },
  98. [/(@simpleRefName)(_{1,2})/, ["string.link", ""]],
  99. [/(`)([^<`]+\s+)(<)(.*)(>)(`)(_)/, ["", "string.link", "", "string.link", "", "", ""]],
  100. [/\*\*([^\\*]|\*(?!\*))+\*\*/, "strong"],
  101. [/\*[^*]+\*/, "emphasis"],
  102. [/(``)((?:[^`]|\`(?!`))+)(``)/, ["", "keyword", ""]],
  103. [/(__\s+)(.+)/, ["", "keyword"]],
  104. [/(:)((?:@simpleRefNameWithoutBq)?)(:`)([^`]+)(`)/, ["", "keyword", "", "", ""]],
  105. [/(`)([^`]+)(`:)((?:@simpleRefNameWithoutBq)?)(:)/, ["", "", "", "keyword", ""]],
  106. [/(`)([^`]+)(`)/, ""],
  107. [/(_`)(@phrase)(`)/, ["", "string.link", ""]]
  108. ],
  109. citations: [
  110. [
  111. /^(\.\.\s+\[)((?:@citationName))(\]\s+)(.*)/,
  112. [{ token: "", next: "@subsequentLines" }, "string.link", "", ""]
  113. ]
  114. ],
  115. citationsReference: [[/(\[)(@citationName)(\]_)/, ["", "string.link", ""]]],
  116. footnotes: [
  117. [
  118. /^(\.\.\s+\[)((?:[0-9]+))(\]\s+.*)/,
  119. [{ token: "", next: "@subsequentLines" }, "string.link", ""]
  120. ],
  121. [
  122. /^(\.\.\s+\[)((?:#@simpleRefName?))(\]\s+)(.*)/,
  123. [{ token: "", next: "@subsequentLines" }, "string.link", "", ""]
  124. ],
  125. [
  126. /^(\.\.\s+\[)((?:\*))(\]\s+)(.*)/,
  127. [{ token: "", next: "@subsequentLines" }, "string.link", "", ""]
  128. ]
  129. ],
  130. footnotesReference: [
  131. [/(\[)([0-9]+)(\])(_)/, ["", "string.link", "", ""]],
  132. [/(\[)(#@simpleRefName?)(\])(_)/, ["", "string.link", "", ""]],
  133. [/(\[)(\*)(\])(_)/, ["", "string.link", "", ""]]
  134. ],
  135. blankLineOfLiteralBlocks: [
  136. [/^$/, "", "@subsequentLinesOfLiteralBlocks"],
  137. [/^.*$/, "", "@pop"]
  138. ],
  139. subsequentLinesOfLiteralBlocks: [
  140. [/(@blockLiteralStart+)(.*)/, ["keyword", ""]],
  141. [/^(?!blockLiteralStart)/, "", "@popall"]
  142. ],
  143. subsequentLines: [
  144. [/^[\s]+.*/, ""],
  145. [/^(?!\s)/, "", "@pop"]
  146. ],
  147. hyperlinks: [
  148. [/^[\s]+.*/, "string.link"],
  149. [/^(?!\s)/, "", "@pop"]
  150. ],
  151. comments: [
  152. [/^[\s]+.*/, "comment"],
  153. [/^(?!\s)/, "", "@pop"]
  154. ],
  155. tables: [
  156. [/\+-[+-]+/, "keyword"],
  157. [/\+=[+=]+/, "keyword"]
  158. ]
  159. }
  160. };
  161. export {
  162. conf,
  163. language
  164. };