markdown.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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/markdown/markdown.ts
  8. var conf = {
  9. comments: {
  10. blockComment: ["<!--", "-->"]
  11. },
  12. brackets: [
  13. ["{", "}"],
  14. ["[", "]"],
  15. ["(", ")"]
  16. ],
  17. autoClosingPairs: [
  18. { open: "{", close: "}" },
  19. { open: "[", close: "]" },
  20. { open: "(", close: ")" },
  21. { open: "<", close: ">", notIn: ["string"] }
  22. ],
  23. surroundingPairs: [
  24. { open: "(", close: ")" },
  25. { open: "[", close: "]" },
  26. { open: "`", close: "`" }
  27. ],
  28. folding: {
  29. markers: {
  30. start: new RegExp("^\\s*<!--\\s*#?region\\b.*-->"),
  31. end: new RegExp("^\\s*<!--\\s*#?endregion\\b.*-->")
  32. }
  33. }
  34. };
  35. var language = {
  36. defaultToken: "",
  37. tokenPostfix: ".md",
  38. control: /[\\`*_\[\]{}()#+\-\.!]/,
  39. noncontrol: /[^\\`*_\[\]{}()#+\-\.!]/,
  40. escapes: /\\(?:@control)/,
  41. jsescapes: /\\(?:[btnfr\\"']|[0-7][0-7]?|[0-3][0-7]{2})/,
  42. empty: [
  43. "area",
  44. "base",
  45. "basefont",
  46. "br",
  47. "col",
  48. "frame",
  49. "hr",
  50. "img",
  51. "input",
  52. "isindex",
  53. "link",
  54. "meta",
  55. "param"
  56. ],
  57. tokenizer: {
  58. root: [
  59. [/^\s*\|/, "@rematch", "@table_header"],
  60. [/^(\s{0,3})(#+)((?:[^\\#]|@escapes)+)((?:#+)?)/, ["white", "keyword", "keyword", "keyword"]],
  61. [/^\s*(=+|\-+)\s*$/, "keyword"],
  62. [/^\s*((\*[ ]?)+)\s*$/, "meta.separator"],
  63. [/^\s*>+/, "comment"],
  64. [/^\s*([\*\-+:]|\d+\.)\s/, "keyword"],
  65. [/^(\t|[ ]{4})[^ ].*$/, "string"],
  66. [/^\s*~~~\s*((?:\w|[\/\-#])+)?\s*$/, { token: "string", next: "@codeblock" }],
  67. [
  68. /^\s*```\s*((?:\w|[\/\-#])+).*$/,
  69. { token: "string", next: "@codeblockgh", nextEmbedded: "$1" }
  70. ],
  71. [/^\s*```\s*$/, { token: "string", next: "@codeblock" }],
  72. { include: "@linecontent" }
  73. ],
  74. table_header: [
  75. { include: "@table_common" },
  76. [/[^\|]+/, "keyword.table.header"]
  77. ],
  78. table_body: [{ include: "@table_common" }, { include: "@linecontent" }],
  79. table_common: [
  80. [/\s*[\-:]+\s*/, { token: "keyword", switchTo: "table_body" }],
  81. [/^\s*\|/, "keyword.table.left"],
  82. [/^\s*[^\|]/, "@rematch", "@pop"],
  83. [/^\s*$/, "@rematch", "@pop"],
  84. [
  85. /\|/,
  86. {
  87. cases: {
  88. "@eos": "keyword.table.right",
  89. "@default": "keyword.table.middle"
  90. }
  91. }
  92. ]
  93. ],
  94. codeblock: [
  95. [/^\s*~~~\s*$/, { token: "string", next: "@pop" }],
  96. [/^\s*```\s*$/, { token: "string", next: "@pop" }],
  97. [/.*$/, "variable.source"]
  98. ],
  99. codeblockgh: [
  100. [/```\s*$/, { token: "string", next: "@pop", nextEmbedded: "@pop" }],
  101. [/[^`]+/, "variable.source"]
  102. ],
  103. linecontent: [
  104. [/&\w+;/, "string.escape"],
  105. [/@escapes/, "escape"],
  106. [/\b__([^\\_]|@escapes|_(?!_))+__\b/, "strong"],
  107. [/\*\*([^\\*]|@escapes|\*(?!\*))+\*\*/, "strong"],
  108. [/\b_[^_]+_\b/, "emphasis"],
  109. [/\*([^\\*]|@escapes)+\*/, "emphasis"],
  110. [/`([^\\`]|@escapes)+`/, "variable"],
  111. [/\{+[^}]+\}+/, "string.target"],
  112. [/(!?\[)((?:[^\]\\]|@escapes)*)(\]\([^\)]+\))/, ["string.link", "", "string.link"]],
  113. [/(!?\[)((?:[^\]\\]|@escapes)*)(\])/, "string.link"],
  114. { include: "html" }
  115. ],
  116. html: [
  117. [/<(\w+)\/>/, "tag"],
  118. [
  119. /<(\w+)/,
  120. {
  121. cases: {
  122. "@empty": { token: "tag", next: "@tag.$1" },
  123. "@default": { token: "tag", next: "@tag.$1" }
  124. }
  125. }
  126. ],
  127. [/<\/(\w+)\s*>/, { token: "tag" }],
  128. [/<!--/, "comment", "@comment"]
  129. ],
  130. comment: [
  131. [/[^<\-]+/, "comment.content"],
  132. [/-->/, "comment", "@pop"],
  133. [/<!--/, "comment.content.invalid"],
  134. [/[<\-]/, "comment.content"]
  135. ],
  136. tag: [
  137. [/[ \t\r\n]+/, "white"],
  138. [
  139. /(type)(\s*=\s*)(")([^"]+)(")/,
  140. [
  141. "attribute.name.html",
  142. "delimiter.html",
  143. "string.html",
  144. { token: "string.html", switchTo: "@tag.$S2.$4" },
  145. "string.html"
  146. ]
  147. ],
  148. [
  149. /(type)(\s*=\s*)(')([^']+)(')/,
  150. [
  151. "attribute.name.html",
  152. "delimiter.html",
  153. "string.html",
  154. { token: "string.html", switchTo: "@tag.$S2.$4" },
  155. "string.html"
  156. ]
  157. ],
  158. [/(\w+)(\s*=\s*)("[^"]*"|'[^']*')/, ["attribute.name.html", "delimiter.html", "string.html"]],
  159. [/\w+/, "attribute.name.html"],
  160. [/\/>/, "tag", "@pop"],
  161. [
  162. />/,
  163. {
  164. cases: {
  165. "$S2==style": {
  166. token: "tag",
  167. switchTo: "embeddedStyle",
  168. nextEmbedded: "text/css"
  169. },
  170. "$S2==script": {
  171. cases: {
  172. $S3: {
  173. token: "tag",
  174. switchTo: "embeddedScript",
  175. nextEmbedded: "$S3"
  176. },
  177. "@default": {
  178. token: "tag",
  179. switchTo: "embeddedScript",
  180. nextEmbedded: "text/javascript"
  181. }
  182. }
  183. },
  184. "@default": { token: "tag", next: "@pop" }
  185. }
  186. }
  187. ]
  188. ],
  189. embeddedStyle: [
  190. [/[^<]+/, ""],
  191. [/<\/style\s*>/, { token: "@rematch", next: "@pop", nextEmbedded: "@pop" }],
  192. [/</, ""]
  193. ],
  194. embeddedScript: [
  195. [/[^<]+/, ""],
  196. [/<\/script\s*>/, { token: "@rematch", next: "@pop", nextEmbedded: "@pop" }],
  197. [/</, ""]
  198. ]
  199. }
  200. };
  201. export {
  202. conf,
  203. language
  204. };