markdown.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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/markdown/markdown',["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. comments: {
  11. blockComment: ['<!--', '-->']
  12. },
  13. brackets: [
  14. ['{', '}'],
  15. ['[', ']'],
  16. ['(', ')']
  17. ],
  18. autoClosingPairs: [
  19. { open: '{', close: '}' },
  20. { open: '[', close: ']' },
  21. { open: '(', close: ')' },
  22. { open: '<', close: '>', notIn: ['string'] }
  23. ],
  24. surroundingPairs: [
  25. { open: '(', close: ')' },
  26. { open: '[', close: ']' },
  27. { open: '`', close: '`' }
  28. ],
  29. folding: {
  30. markers: {
  31. start: new RegExp('^\\s*<!--\\s*#?region\\b.*-->'),
  32. end: new RegExp('^\\s*<!--\\s*#?endregion\\b.*-->')
  33. }
  34. }
  35. };
  36. exports.language = {
  37. defaultToken: '',
  38. tokenPostfix: '.md',
  39. // escape codes
  40. control: /[\\`*_\[\]{}()#+\-\.!]/,
  41. noncontrol: /[^\\`*_\[\]{}()#+\-\.!]/,
  42. escapes: /\\(?:@control)/,
  43. // escape codes for javascript/CSS strings
  44. jsescapes: /\\(?:[btnfr\\"']|[0-7][0-7]?|[0-3][0-7]{2})/,
  45. // non matched elements
  46. empty: [
  47. 'area',
  48. 'base',
  49. 'basefont',
  50. 'br',
  51. 'col',
  52. 'frame',
  53. 'hr',
  54. 'img',
  55. 'input',
  56. 'isindex',
  57. 'link',
  58. 'meta',
  59. 'param'
  60. ],
  61. tokenizer: {
  62. root: [
  63. // markdown tables
  64. [/^\s*\|/, '@rematch', '@table_header'],
  65. // headers (with #)
  66. [
  67. /^(\s{0,3})(#+)((?:[^\\#]|@escapes)+)((?:#+)?)/,
  68. ['white', 'keyword', 'keyword', 'keyword']
  69. ],
  70. // headers (with =)
  71. [/^\s*(=+|\-+)\s*$/, 'keyword'],
  72. // headers (with ***)
  73. [/^\s*((\*[ ]?)+)\s*$/, 'meta.separator'],
  74. // quote
  75. [/^\s*>+/, 'comment'],
  76. // list (starting with * or number)
  77. [/^\s*([\*\-+:]|\d+\.)\s/, 'keyword'],
  78. // code block (4 spaces indent)
  79. [/^(\t|[ ]{4})[^ ].*$/, 'string'],
  80. // code block (3 tilde)
  81. [/^\s*~~~\s*((?:\w|[\/\-#])+)?\s*$/, { token: 'string', next: '@codeblock' }],
  82. // github style code blocks (with backticks and language)
  83. [
  84. /^\s*```\s*((?:\w|[\/\-#])+).*$/,
  85. { token: 'string', next: '@codeblockgh', nextEmbedded: '$1' }
  86. ],
  87. // github style code blocks (with backticks but no language)
  88. [/^\s*```\s*$/, { token: 'string', next: '@codeblock' }],
  89. // markup within lines
  90. { include: '@linecontent' }
  91. ],
  92. table_header: [
  93. { include: '@table_common' },
  94. [/[^\|]+/, 'keyword.table.header'] // table header
  95. ],
  96. table_body: [{ include: '@table_common' }, { include: '@linecontent' }],
  97. table_common: [
  98. [/\s*[\-:]+\s*/, { token: 'keyword', switchTo: 'table_body' }],
  99. [/^\s*\|/, 'keyword.table.left'],
  100. [/^\s*[^\|]/, '@rematch', '@pop'],
  101. [/^\s*$/, '@rematch', '@pop'],
  102. [
  103. /\|/,
  104. {
  105. cases: {
  106. '@eos': 'keyword.table.right',
  107. '@default': 'keyword.table.middle' // inner |
  108. }
  109. }
  110. ]
  111. ],
  112. codeblock: [
  113. [/^\s*~~~\s*$/, { token: 'string', next: '@pop' }],
  114. [/^\s*```\s*$/, { token: 'string', next: '@pop' }],
  115. [/.*$/, 'variable.source']
  116. ],
  117. // github style code blocks
  118. codeblockgh: [
  119. [/```\s*$/, { token: 'string', next: '@pop', nextEmbedded: '@pop' }],
  120. [/[^`]+/, 'variable.source']
  121. ],
  122. linecontent: [
  123. // escapes
  124. [/&\w+;/, 'string.escape'],
  125. [/@escapes/, 'escape'],
  126. // various markup
  127. [/\b__([^\\_]|@escapes|_(?!_))+__\b/, 'strong'],
  128. [/\*\*([^\\*]|@escapes|\*(?!\*))+\*\*/, 'strong'],
  129. [/\b_[^_]+_\b/, 'emphasis'],
  130. [/\*([^\\*]|@escapes)+\*/, 'emphasis'],
  131. [/`([^\\`]|@escapes)+`/, 'variable'],
  132. // links
  133. [/\{+[^}]+\}+/, 'string.target'],
  134. [/(!?\[)((?:[^\]\\]|@escapes)*)(\]\([^\)]+\))/, ['string.link', '', 'string.link']],
  135. [/(!?\[)((?:[^\]\\]|@escapes)*)(\])/, 'string.link'],
  136. // or html
  137. { include: 'html' }
  138. ],
  139. // Note: it is tempting to rather switch to the real HTML mode instead of building our own here
  140. // but currently there is a limitation in Monarch that prevents us from doing it: The opening
  141. // '<' would start the HTML mode, however there is no way to jump 1 character back to let the
  142. // HTML mode also tokenize the opening angle bracket. Thus, even though we could jump to HTML,
  143. // we cannot correctly tokenize it in that mode yet.
  144. html: [
  145. // html tags
  146. [/<(\w+)\/>/, 'tag'],
  147. [
  148. /<(\w+)/,
  149. {
  150. cases: {
  151. '@empty': { token: 'tag', next: '@tag.$1' },
  152. '@default': { token: 'tag', next: '@tag.$1' }
  153. }
  154. }
  155. ],
  156. [/<\/(\w+)\s*>/, { token: 'tag' }],
  157. [/<!--/, 'comment', '@comment']
  158. ],
  159. comment: [
  160. [/[^<\-]+/, 'comment.content'],
  161. [/-->/, 'comment', '@pop'],
  162. [/<!--/, 'comment.content.invalid'],
  163. [/[<\-]/, 'comment.content']
  164. ],
  165. // Almost full HTML tag matching, complete with embedded scripts & styles
  166. tag: [
  167. [/[ \t\r\n]+/, 'white'],
  168. [
  169. /(type)(\s*=\s*)(")([^"]+)(")/,
  170. [
  171. 'attribute.name.html',
  172. 'delimiter.html',
  173. 'string.html',
  174. { token: 'string.html', switchTo: '@tag.$S2.$4' },
  175. 'string.html'
  176. ]
  177. ],
  178. [
  179. /(type)(\s*=\s*)(')([^']+)(')/,
  180. [
  181. 'attribute.name.html',
  182. 'delimiter.html',
  183. 'string.html',
  184. { token: 'string.html', switchTo: '@tag.$S2.$4' },
  185. 'string.html'
  186. ]
  187. ],
  188. [
  189. /(\w+)(\s*=\s*)("[^"]*"|'[^']*')/,
  190. ['attribute.name.html', 'delimiter.html', 'string.html']
  191. ],
  192. [/\w+/, 'attribute.name.html'],
  193. [/\/>/, 'tag', '@pop'],
  194. [
  195. />/,
  196. {
  197. cases: {
  198. '$S2==style': {
  199. token: 'tag',
  200. switchTo: 'embeddedStyle',
  201. nextEmbedded: 'text/css'
  202. },
  203. '$S2==script': {
  204. cases: {
  205. $S3: {
  206. token: 'tag',
  207. switchTo: 'embeddedScript',
  208. nextEmbedded: '$S3'
  209. },
  210. '@default': {
  211. token: 'tag',
  212. switchTo: 'embeddedScript',
  213. nextEmbedded: 'text/javascript'
  214. }
  215. }
  216. },
  217. '@default': { token: 'tag', next: '@pop' }
  218. }
  219. }
  220. ]
  221. ],
  222. embeddedStyle: [
  223. [/[^<]+/, ''],
  224. [/<\/style\s*>/, { token: '@rematch', next: '@pop', nextEmbedded: '@pop' }],
  225. [/</, '']
  226. ],
  227. embeddedScript: [
  228. [/[^<]+/, ''],
  229. [/<\/script\s*>/, { token: '@rematch', next: '@pop', nextEmbedded: '@pop' }],
  230. [/</, '']
  231. ]
  232. }
  233. };
  234. });