marked.esm.js 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830
  1. /**
  2. * marked - a markdown parser
  3. * Copyright (c) 2011-2020, Christopher Jeffrey. (MIT Licensed)
  4. * https://github.com/markedjs/marked
  5. */
  6. /**
  7. * DO NOT EDIT THIS FILE
  8. * The code in this file is generated from files in ./src/
  9. */
  10. function createCommonjsModule(fn, module) {
  11. return module = { exports: {} }, fn(module, module.exports), module.exports;
  12. }
  13. var defaults = createCommonjsModule(function (module) {
  14. function getDefaults() {
  15. return {
  16. baseUrl: null,
  17. breaks: false,
  18. gfm: true,
  19. headerIds: true,
  20. headerPrefix: '',
  21. highlight: null,
  22. langPrefix: 'language-',
  23. mangle: true,
  24. pedantic: false,
  25. renderer: null,
  26. sanitize: false,
  27. sanitizer: null,
  28. silent: false,
  29. smartLists: false,
  30. smartypants: false,
  31. xhtml: false
  32. };
  33. }
  34. function changeDefaults(newDefaults) {
  35. module.exports.defaults = newDefaults;
  36. }
  37. module.exports = {
  38. defaults: getDefaults(),
  39. getDefaults,
  40. changeDefaults
  41. };
  42. });
  43. var defaults_1 = defaults.defaults;
  44. var defaults_2 = defaults.getDefaults;
  45. var defaults_3 = defaults.changeDefaults;
  46. /**
  47. * Helpers
  48. */
  49. const escapeTest = /[&<>"']/;
  50. const escapeReplace = /[&<>"']/g;
  51. const escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/;
  52. const escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g;
  53. const escapeReplacements = {
  54. '&': '&amp;',
  55. '<': '&lt;',
  56. '>': '&gt;',
  57. '"': '&quot;',
  58. "'": '&#39;'
  59. };
  60. const getEscapeReplacement = (ch) => escapeReplacements[ch];
  61. function escape(html, encode) {
  62. if (encode) {
  63. if (escapeTest.test(html)) {
  64. return html.replace(escapeReplace, getEscapeReplacement);
  65. }
  66. } else {
  67. if (escapeTestNoEncode.test(html)) {
  68. return html.replace(escapeReplaceNoEncode, getEscapeReplacement);
  69. }
  70. }
  71. return html;
  72. }
  73. const unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
  74. function unescape(html) {
  75. // explicitly match decimal, hex, and named HTML entities
  76. return html.replace(unescapeTest, (_, n) => {
  77. n = n.toLowerCase();
  78. if (n === 'colon') return ':';
  79. if (n.charAt(0) === '#') {
  80. return n.charAt(1) === 'x'
  81. ? String.fromCharCode(parseInt(n.substring(2), 16))
  82. : String.fromCharCode(+n.substring(1));
  83. }
  84. return '';
  85. });
  86. }
  87. const caret = /(^|[^\[])\^/g;
  88. function edit(regex, opt) {
  89. regex = regex.source || regex;
  90. opt = opt || '';
  91. const obj = {
  92. replace: (name, val) => {
  93. val = val.source || val;
  94. val = val.replace(caret, '$1');
  95. regex = regex.replace(name, val);
  96. return obj;
  97. },
  98. getRegex: () => {
  99. return new RegExp(regex, opt);
  100. }
  101. };
  102. return obj;
  103. }
  104. const nonWordAndColonTest = /[^\w:]/g;
  105. const originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
  106. function cleanUrl(sanitize, base, href) {
  107. if (sanitize) {
  108. let prot;
  109. try {
  110. prot = decodeURIComponent(unescape(href))
  111. .replace(nonWordAndColonTest, '')
  112. .toLowerCase();
  113. } catch (e) {
  114. return null;
  115. }
  116. if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
  117. return null;
  118. }
  119. }
  120. if (base && !originIndependentUrl.test(href)) {
  121. href = resolveUrl(base, href);
  122. }
  123. try {
  124. href = encodeURI(href).replace(/%25/g, '%');
  125. } catch (e) {
  126. return null;
  127. }
  128. return href;
  129. }
  130. const baseUrls = {};
  131. const justDomain = /^[^:]+:\/*[^/]*$/;
  132. const protocol = /^([^:]+:)[\s\S]*$/;
  133. const domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
  134. function resolveUrl(base, href) {
  135. if (!baseUrls[' ' + base]) {
  136. // we can ignore everything in base after the last slash of its path component,
  137. // but we might need to add _that_
  138. // https://tools.ietf.org/html/rfc3986#section-3
  139. if (justDomain.test(base)) {
  140. baseUrls[' ' + base] = base + '/';
  141. } else {
  142. baseUrls[' ' + base] = rtrim(base, '/', true);
  143. }
  144. }
  145. base = baseUrls[' ' + base];
  146. const relativeBase = base.indexOf(':') === -1;
  147. if (href.substring(0, 2) === '//') {
  148. if (relativeBase) {
  149. return href;
  150. }
  151. return base.replace(protocol, '$1') + href;
  152. } else if (href.charAt(0) === '/') {
  153. if (relativeBase) {
  154. return href;
  155. }
  156. return base.replace(domain, '$1') + href;
  157. } else {
  158. return base + href;
  159. }
  160. }
  161. const noopTest = { exec: function noopTest() {} };
  162. function merge(obj) {
  163. let i = 1,
  164. target,
  165. key;
  166. for (; i < arguments.length; i++) {
  167. target = arguments[i];
  168. for (key in target) {
  169. if (Object.prototype.hasOwnProperty.call(target, key)) {
  170. obj[key] = target[key];
  171. }
  172. }
  173. }
  174. return obj;
  175. }
  176. function splitCells(tableRow, count) {
  177. // ensure that every cell-delimiting pipe has a space
  178. // before it to distinguish it from an escaped pipe
  179. const row = tableRow.replace(/\|/g, (match, offset, str) => {
  180. let escaped = false,
  181. curr = offset;
  182. while (--curr >= 0 && str[curr] === '\\') escaped = !escaped;
  183. if (escaped) {
  184. // odd number of slashes means | is escaped
  185. // so we leave it alone
  186. return '|';
  187. } else {
  188. // add space before unescaped |
  189. return ' |';
  190. }
  191. }),
  192. cells = row.split(/ \|/);
  193. let i = 0;
  194. if (cells.length > count) {
  195. cells.splice(count);
  196. } else {
  197. while (cells.length < count) cells.push('');
  198. }
  199. for (; i < cells.length; i++) {
  200. // leading or trailing whitespace is ignored per the gfm spec
  201. cells[i] = cells[i].trim().replace(/\\\|/g, '|');
  202. }
  203. return cells;
  204. }
  205. // Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
  206. // /c*$/ is vulnerable to REDOS.
  207. // invert: Remove suffix of non-c chars instead. Default falsey.
  208. function rtrim(str, c, invert) {
  209. const l = str.length;
  210. if (l === 0) {
  211. return '';
  212. }
  213. // Length of suffix matching the invert condition.
  214. let suffLen = 0;
  215. // Step left until we fail to match the invert condition.
  216. while (suffLen < l) {
  217. const currChar = str.charAt(l - suffLen - 1);
  218. if (currChar === c && !invert) {
  219. suffLen++;
  220. } else if (currChar !== c && invert) {
  221. suffLen++;
  222. } else {
  223. break;
  224. }
  225. }
  226. return str.substr(0, l - suffLen);
  227. }
  228. function findClosingBracket(str, b) {
  229. if (str.indexOf(b[1]) === -1) {
  230. return -1;
  231. }
  232. const l = str.length;
  233. let level = 0,
  234. i = 0;
  235. for (; i < l; i++) {
  236. if (str[i] === '\\') {
  237. i++;
  238. } else if (str[i] === b[0]) {
  239. level++;
  240. } else if (str[i] === b[1]) {
  241. level--;
  242. if (level < 0) {
  243. return i;
  244. }
  245. }
  246. }
  247. return -1;
  248. }
  249. function checkSanitizeDeprecation(opt) {
  250. if (opt && opt.sanitize && !opt.silent) {
  251. console.warn('marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options');
  252. }
  253. }
  254. var helpers = {
  255. escape,
  256. unescape,
  257. edit,
  258. cleanUrl,
  259. resolveUrl,
  260. noopTest,
  261. merge,
  262. splitCells,
  263. rtrim,
  264. findClosingBracket,
  265. checkSanitizeDeprecation
  266. };
  267. const {
  268. noopTest: noopTest$1,
  269. edit: edit$1,
  270. merge: merge$1
  271. } = helpers;
  272. /**
  273. * Block-Level Grammar
  274. */
  275. const block = {
  276. newline: /^\n+/,
  277. code: /^( {4}[^\n]+\n*)+/,
  278. fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,
  279. hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
  280. heading: /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/,
  281. blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
  282. list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
  283. html: '^ {0,3}(?:' // optional indentation
  284. + '<(script|pre|style)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
  285. + '|comment[^\\n]*(\\n+|$)' // (2)
  286. + '|<\\?[\\s\\S]*?\\?>\\n*' // (3)
  287. + '|<![A-Z][\\s\\S]*?>\\n*' // (4)
  288. + '|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>\\n*' // (5)
  289. + '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:\\n{2,}|$)' // (6)
  290. + '|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag
  291. + '|</(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag
  292. + ')',
  293. def: /^ {0,3}\[(label)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,
  294. nptable: noopTest$1,
  295. table: noopTest$1,
  296. lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,
  297. // regex template, placeholders will be replaced according to different paragraph
  298. // interruption rules of commonmark and the original markdown spec:
  299. _paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/,
  300. text: /^[^\n]+/
  301. };
  302. block._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/;
  303. block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/;
  304. block.def = edit$1(block.def)
  305. .replace('label', block._label)
  306. .replace('title', block._title)
  307. .getRegex();
  308. block.bullet = /(?:[*+-]|\d{1,9}\.)/;
  309. block.item = /^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/;
  310. block.item = edit$1(block.item, 'gm')
  311. .replace(/bull/g, block.bullet)
  312. .getRegex();
  313. block.list = edit$1(block.list)
  314. .replace(/bull/g, block.bullet)
  315. .replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))')
  316. .replace('def', '\\n+(?=' + block.def.source + ')')
  317. .getRegex();
  318. block._tag = 'address|article|aside|base|basefont|blockquote|body|caption'
  319. + '|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption'
  320. + '|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe'
  321. + '|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option'
  322. + '|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr'
  323. + '|track|ul';
  324. block._comment = /<!--(?!-?>)[\s\S]*?-->/;
  325. block.html = edit$1(block.html, 'i')
  326. .replace('comment', block._comment)
  327. .replace('tag', block._tag)
  328. .replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/)
  329. .getRegex();
  330. block.paragraph = edit$1(block._paragraph)
  331. .replace('hr', block.hr)
  332. .replace('heading', ' {0,3}#{1,6} ')
  333. .replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
  334. .replace('blockquote', ' {0,3}>')
  335. .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
  336. .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
  337. .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)')
  338. .replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
  339. .getRegex();
  340. block.blockquote = edit$1(block.blockquote)
  341. .replace('paragraph', block.paragraph)
  342. .getRegex();
  343. /**
  344. * Normal Block Grammar
  345. */
  346. block.normal = merge$1({}, block);
  347. /**
  348. * GFM Block Grammar
  349. */
  350. block.gfm = merge$1({}, block.normal, {
  351. nptable: /^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/,
  352. table: '^ *\\|(.+)\\n' // Header
  353. + ' *\\|?( *[-:]+[-| :]*)' // Align
  354. + '(?:\\n((?:(?!^|>|\\n| |hr|heading|lheading|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells
  355. });
  356. block.gfm.table = edit$1(block.gfm.table)
  357. .replace('hr', block.hr)
  358. .replace('heading', ' {0,3}#{1,6} ')
  359. .replace('lheading', '([^\\n]+)\\n {0,3}(=+|-+) *(?:\\n+|$)')
  360. .replace('blockquote', ' {0,3}>')
  361. .replace('code', ' {4}[^\\n]')
  362. .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
  363. .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
  364. .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)')
  365. .replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
  366. .getRegex();
  367. /**
  368. * Pedantic grammar (original John Gruber's loose markdown specification)
  369. */
  370. block.pedantic = merge$1({}, block.normal, {
  371. html: edit$1(
  372. '^ *(?:comment *(?:\\n|\\s*$)'
  373. + '|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)' // closed tag
  374. + '|<tag(?:"[^"]*"|\'[^\']*\'|\\s[^\'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))')
  375. .replace('comment', block._comment)
  376. .replace(/tag/g, '(?!(?:'
  377. + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub'
  378. + '|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)'
  379. + '\\b)\\w+(?!:|[^\\w\\s@]*@)\\b')
  380. .getRegex(),
  381. def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
  382. heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/,
  383. fences: noopTest$1, // fences not supported
  384. paragraph: edit$1(block.normal._paragraph)
  385. .replace('hr', block.hr)
  386. .replace('heading', ' *#{1,6} *[^\n]')
  387. .replace('lheading', block.lheading)
  388. .replace('blockquote', ' {0,3}>')
  389. .replace('|fences', '')
  390. .replace('|list', '')
  391. .replace('|html', '')
  392. .getRegex()
  393. });
  394. /**
  395. * Inline-Level Grammar
  396. */
  397. const inline = {
  398. escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,
  399. autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
  400. url: noopTest$1,
  401. tag: '^comment'
  402. + '|^</[a-zA-Z][\\w:-]*\\s*>' // self-closing tag
  403. + '|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>' // open tag
  404. + '|^<\\?[\\s\\S]*?\\?>' // processing instruction, e.g. <?php ?>
  405. + '|^<![a-zA-Z]+\\s[\\s\\S]*?>' // declaration, e.g. <!DOCTYPE html>
  406. + '|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>', // CDATA section
  407. link: /^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,
  408. reflink: /^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,
  409. nolink: /^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,
  410. strong: /^__([^\s_])__(?!_)|^\*\*([^\s*])\*\*(?!\*)|^__([^\s][\s\S]*?[^\s])__(?!_)|^\*\*([^\s][\s\S]*?[^\s])\*\*(?!\*)/,
  411. em: /^_([^\s_])_(?!_)|^\*([^\s*<\[])\*(?!\*)|^_([^\s<][\s\S]*?[^\s_])_(?!_|[^\spunctuation])|^_([^\s_<][\s\S]*?[^\s])_(?!_|[^\spunctuation])|^\*([^\s<"][\s\S]*?[^\s\*])\*(?!\*|[^\spunctuation])|^\*([^\s*"<\[][\s\S]*?[^\s])\*(?!\*)/,
  412. code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
  413. br: /^( {2,}|\\)\n(?!\s*$)/,
  414. del: noopTest$1,
  415. text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*]|\b_|$)|[^ ](?= {2,}\n))|(?= {2,}\n))/
  416. };
  417. // list of punctuation marks from common mark spec
  418. // without ` and ] to workaround Rule 17 (inline code blocks/links)
  419. inline._punctuation = '!"#$%&\'()*+,\\-./:;<=>?@\\[^_{|}~';
  420. inline.em = edit$1(inline.em).replace(/punctuation/g, inline._punctuation).getRegex();
  421. inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g;
  422. inline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
  423. inline._email = /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/;
  424. inline.autolink = edit$1(inline.autolink)
  425. .replace('scheme', inline._scheme)
  426. .replace('email', inline._email)
  427. .getRegex();
  428. inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/;
  429. inline.tag = edit$1(inline.tag)
  430. .replace('comment', block._comment)
  431. .replace('attribute', inline._attribute)
  432. .getRegex();
  433. inline._label = /(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
  434. inline._href = /<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/;
  435. inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/;
  436. inline.link = edit$1(inline.link)
  437. .replace('label', inline._label)
  438. .replace('href', inline._href)
  439. .replace('title', inline._title)
  440. .getRegex();
  441. inline.reflink = edit$1(inline.reflink)
  442. .replace('label', inline._label)
  443. .getRegex();
  444. /**
  445. * Normal Inline Grammar
  446. */
  447. inline.normal = merge$1({}, inline);
  448. /**
  449. * Pedantic Inline Grammar
  450. */
  451. inline.pedantic = merge$1({}, inline.normal, {
  452. strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
  453. em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,
  454. link: edit$1(/^!?\[(label)\]\((.*?)\)/)
  455. .replace('label', inline._label)
  456. .getRegex(),
  457. reflink: edit$1(/^!?\[(label)\]\s*\[([^\]]*)\]/)
  458. .replace('label', inline._label)
  459. .getRegex()
  460. });
  461. /**
  462. * GFM Inline Grammar
  463. */
  464. inline.gfm = merge$1({}, inline.normal, {
  465. escape: edit$1(inline.escape).replace('])', '~|])').getRegex(),
  466. _extended_email: /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,
  467. url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
  468. _backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,
  469. del: /^~+(?=\S)([\s\S]*?\S)~+/,
  470. text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*~]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))|(?= {2,}\n|[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))/
  471. });
  472. inline.gfm.url = edit$1(inline.gfm.url, 'i')
  473. .replace('email', inline.gfm._extended_email)
  474. .getRegex();
  475. /**
  476. * GFM + Line Breaks Inline Grammar
  477. */
  478. inline.breaks = merge$1({}, inline.gfm, {
  479. br: edit$1(inline.br).replace('{2,}', '*').getRegex(),
  480. text: edit$1(inline.gfm.text)
  481. .replace('\\b_', '\\b_| {2,}\\n')
  482. .replace(/\{2,\}/g, '*')
  483. .getRegex()
  484. });
  485. var rules = {
  486. block,
  487. inline
  488. };
  489. const { defaults: defaults$1 } = defaults;
  490. const { block: block$1 } = rules;
  491. const {
  492. rtrim: rtrim$1,
  493. splitCells: splitCells$1,
  494. escape: escape$1
  495. } = helpers;
  496. /**
  497. * Block Lexer
  498. */
  499. var Lexer_1 = class Lexer {
  500. constructor(options) {
  501. this.tokens = [];
  502. this.tokens.links = Object.create(null);
  503. this.options = options || defaults$1;
  504. this.rules = block$1.normal;
  505. if (this.options.pedantic) {
  506. this.rules = block$1.pedantic;
  507. } else if (this.options.gfm) {
  508. this.rules = block$1.gfm;
  509. }
  510. }
  511. /**
  512. * Expose Block Rules
  513. */
  514. static get rules() {
  515. return block$1;
  516. }
  517. /**
  518. * Static Lex Method
  519. */
  520. static lex(src, options) {
  521. const lexer = new Lexer(options);
  522. return lexer.lex(src);
  523. };
  524. /**
  525. * Preprocessing
  526. */
  527. lex(src) {
  528. src = src
  529. .replace(/\r\n|\r/g, '\n')
  530. .replace(/\t/g, ' ');
  531. return this.token(src, true);
  532. };
  533. /**
  534. * Lexing
  535. */
  536. token(src, top) {
  537. src = src.replace(/^ +$/gm, '');
  538. let next,
  539. loose,
  540. cap,
  541. bull,
  542. b,
  543. item,
  544. listStart,
  545. listItems,
  546. t,
  547. space,
  548. i,
  549. tag,
  550. l,
  551. isordered,
  552. istask,
  553. ischecked;
  554. while (src) {
  555. // newline
  556. if (cap = this.rules.newline.exec(src)) {
  557. src = src.substring(cap[0].length);
  558. if (cap[0].length > 1) {
  559. this.tokens.push({
  560. type: 'space'
  561. });
  562. }
  563. }
  564. // code
  565. if (cap = this.rules.code.exec(src)) {
  566. const lastToken = this.tokens[this.tokens.length - 1];
  567. src = src.substring(cap[0].length);
  568. // An indented code block cannot interrupt a paragraph.
  569. if (lastToken && lastToken.type === 'paragraph') {
  570. lastToken.text += '\n' + cap[0].trimRight();
  571. } else {
  572. cap = cap[0].replace(/^ {4}/gm, '');
  573. this.tokens.push({
  574. type: 'code',
  575. codeBlockStyle: 'indented',
  576. text: !this.options.pedantic
  577. ? rtrim$1(cap, '\n')
  578. : cap
  579. });
  580. }
  581. continue;
  582. }
  583. // fences
  584. if (cap = this.rules.fences.exec(src)) {
  585. src = src.substring(cap[0].length);
  586. this.tokens.push({
  587. type: 'code',
  588. lang: cap[2] ? cap[2].trim() : cap[2],
  589. text: cap[3] || ''
  590. });
  591. continue;
  592. }
  593. // heading
  594. if (cap = this.rules.heading.exec(src)) {
  595. src = src.substring(cap[0].length);
  596. this.tokens.push({
  597. type: 'heading',
  598. depth: cap[1].length,
  599. text: cap[2]
  600. });
  601. continue;
  602. }
  603. // table no leading pipe (gfm)
  604. if (cap = this.rules.nptable.exec(src)) {
  605. item = {
  606. type: 'table',
  607. header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')),
  608. align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
  609. cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
  610. };
  611. if (item.header.length === item.align.length) {
  612. src = src.substring(cap[0].length);
  613. for (i = 0; i < item.align.length; i++) {
  614. if (/^ *-+: *$/.test(item.align[i])) {
  615. item.align[i] = 'right';
  616. } else if (/^ *:-+: *$/.test(item.align[i])) {
  617. item.align[i] = 'center';
  618. } else if (/^ *:-+ *$/.test(item.align[i])) {
  619. item.align[i] = 'left';
  620. } else {
  621. item.align[i] = null;
  622. }
  623. }
  624. for (i = 0; i < item.cells.length; i++) {
  625. item.cells[i] = splitCells$1(item.cells[i], item.header.length);
  626. }
  627. this.tokens.push(item);
  628. continue;
  629. }
  630. }
  631. // hr
  632. if (cap = this.rules.hr.exec(src)) {
  633. src = src.substring(cap[0].length);
  634. this.tokens.push({
  635. type: 'hr'
  636. });
  637. continue;
  638. }
  639. // blockquote
  640. if (cap = this.rules.blockquote.exec(src)) {
  641. src = src.substring(cap[0].length);
  642. this.tokens.push({
  643. type: 'blockquote_start'
  644. });
  645. cap = cap[0].replace(/^ *> ?/gm, '');
  646. // Pass `top` to keep the current
  647. // "toplevel" state. This is exactly
  648. // how markdown.pl works.
  649. this.token(cap, top);
  650. this.tokens.push({
  651. type: 'blockquote_end'
  652. });
  653. continue;
  654. }
  655. // list
  656. if (cap = this.rules.list.exec(src)) {
  657. src = src.substring(cap[0].length);
  658. bull = cap[2];
  659. isordered = bull.length > 1;
  660. listStart = {
  661. type: 'list_start',
  662. ordered: isordered,
  663. start: isordered ? +bull : '',
  664. loose: false
  665. };
  666. this.tokens.push(listStart);
  667. // Get each top-level item.
  668. cap = cap[0].match(this.rules.item);
  669. listItems = [];
  670. next = false;
  671. l = cap.length;
  672. i = 0;
  673. for (; i < l; i++) {
  674. item = cap[i];
  675. // Remove the list item's bullet
  676. // so it is seen as the next token.
  677. space = item.length;
  678. item = item.replace(/^ *([*+-]|\d+\.) */, '');
  679. // Outdent whatever the
  680. // list item contains. Hacky.
  681. if (~item.indexOf('\n ')) {
  682. space -= item.length;
  683. item = !this.options.pedantic
  684. ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '')
  685. : item.replace(/^ {1,4}/gm, '');
  686. }
  687. // Determine whether the next list item belongs here.
  688. // Backpedal if it does not belong in this list.
  689. if (i !== l - 1) {
  690. b = block$1.bullet.exec(cap[i + 1])[0];
  691. if (bull.length > 1 ? b.length === 1
  692. : (b.length > 1 || (this.options.smartLists && b !== bull))) {
  693. src = cap.slice(i + 1).join('\n') + src;
  694. i = l - 1;
  695. }
  696. }
  697. // Determine whether item is loose or not.
  698. // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
  699. // for discount behavior.
  700. loose = next || /\n\n(?!\s*$)/.test(item);
  701. if (i !== l - 1) {
  702. next = item.charAt(item.length - 1) === '\n';
  703. if (!loose) loose = next;
  704. }
  705. if (loose) {
  706. listStart.loose = true;
  707. }
  708. // Check for task list items
  709. istask = /^\[[ xX]\] /.test(item);
  710. ischecked = undefined;
  711. if (istask) {
  712. ischecked = item[1] !== ' ';
  713. item = item.replace(/^\[[ xX]\] +/, '');
  714. }
  715. t = {
  716. type: 'list_item_start',
  717. task: istask,
  718. checked: ischecked,
  719. loose: loose
  720. };
  721. listItems.push(t);
  722. this.tokens.push(t);
  723. // Recurse.
  724. this.token(item, false);
  725. this.tokens.push({
  726. type: 'list_item_end'
  727. });
  728. }
  729. if (listStart.loose) {
  730. l = listItems.length;
  731. i = 0;
  732. for (; i < l; i++) {
  733. listItems[i].loose = true;
  734. }
  735. }
  736. this.tokens.push({
  737. type: 'list_end'
  738. });
  739. continue;
  740. }
  741. // html
  742. if (cap = this.rules.html.exec(src)) {
  743. src = src.substring(cap[0].length);
  744. this.tokens.push({
  745. type: this.options.sanitize
  746. ? 'paragraph'
  747. : 'html',
  748. pre: !this.options.sanitizer
  749. && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
  750. text: this.options.sanitize ? (this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$1(cap[0])) : cap[0]
  751. });
  752. continue;
  753. }
  754. // def
  755. if (top && (cap = this.rules.def.exec(src))) {
  756. src = src.substring(cap[0].length);
  757. if (cap[3]) cap[3] = cap[3].substring(1, cap[3].length - 1);
  758. tag = cap[1].toLowerCase().replace(/\s+/g, ' ');
  759. if (!this.tokens.links[tag]) {
  760. this.tokens.links[tag] = {
  761. href: cap[2],
  762. title: cap[3]
  763. };
  764. }
  765. continue;
  766. }
  767. // table (gfm)
  768. if (cap = this.rules.table.exec(src)) {
  769. item = {
  770. type: 'table',
  771. header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')),
  772. align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
  773. cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
  774. };
  775. if (item.header.length === item.align.length) {
  776. src = src.substring(cap[0].length);
  777. for (i = 0; i < item.align.length; i++) {
  778. if (/^ *-+: *$/.test(item.align[i])) {
  779. item.align[i] = 'right';
  780. } else if (/^ *:-+: *$/.test(item.align[i])) {
  781. item.align[i] = 'center';
  782. } else if (/^ *:-+ *$/.test(item.align[i])) {
  783. item.align[i] = 'left';
  784. } else {
  785. item.align[i] = null;
  786. }
  787. }
  788. for (i = 0; i < item.cells.length; i++) {
  789. item.cells[i] = splitCells$1(
  790. item.cells[i].replace(/^ *\| *| *\| *$/g, ''),
  791. item.header.length);
  792. }
  793. this.tokens.push(item);
  794. continue;
  795. }
  796. }
  797. // lheading
  798. if (cap = this.rules.lheading.exec(src)) {
  799. src = src.substring(cap[0].length);
  800. this.tokens.push({
  801. type: 'heading',
  802. depth: cap[2].charAt(0) === '=' ? 1 : 2,
  803. text: cap[1]
  804. });
  805. continue;
  806. }
  807. // top-level paragraph
  808. if (top && (cap = this.rules.paragraph.exec(src))) {
  809. src = src.substring(cap[0].length);
  810. this.tokens.push({
  811. type: 'paragraph',
  812. text: cap[1].charAt(cap[1].length - 1) === '\n'
  813. ? cap[1].slice(0, -1)
  814. : cap[1]
  815. });
  816. continue;
  817. }
  818. // text
  819. if (cap = this.rules.text.exec(src)) {
  820. // Top-level should never reach here.
  821. src = src.substring(cap[0].length);
  822. this.tokens.push({
  823. type: 'text',
  824. text: cap[0]
  825. });
  826. continue;
  827. }
  828. if (src) {
  829. throw new Error('Infinite loop on byte: ' + src.charCodeAt(0));
  830. }
  831. }
  832. return this.tokens;
  833. };
  834. };
  835. const { defaults: defaults$2 } = defaults;
  836. const {
  837. cleanUrl: cleanUrl$1,
  838. escape: escape$2
  839. } = helpers;
  840. /**
  841. * Renderer
  842. */
  843. var Renderer_1 = class Renderer {
  844. constructor(options) {
  845. this.options = options || defaults$2;
  846. }
  847. code(code, infostring, escaped) {
  848. const lang = (infostring || '').match(/\S*/)[0];
  849. if (this.options.highlight) {
  850. const out = this.options.highlight(code, lang);
  851. if (out != null && out !== code) {
  852. escaped = true;
  853. code = out;
  854. }
  855. }
  856. if (!lang) {
  857. return '<pre><code>'
  858. + (escaped ? code : escape$2(code, true))
  859. + '</code></pre>';
  860. }
  861. return '<pre><code class="'
  862. + this.options.langPrefix
  863. + escape$2(lang, true)
  864. + '">'
  865. + (escaped ? code : escape$2(code, true))
  866. + '</code></pre>\n';
  867. };
  868. blockquote(quote) {
  869. return '<blockquote>\n' + quote + '</blockquote>\n';
  870. };
  871. html(html) {
  872. return html;
  873. };
  874. heading(text, level, raw, slugger) {
  875. if (this.options.headerIds) {
  876. return '<h'
  877. + level
  878. + ' id="'
  879. + this.options.headerPrefix
  880. + slugger.slug(raw)
  881. + '">'
  882. + text
  883. + '</h'
  884. + level
  885. + '>\n';
  886. }
  887. // ignore IDs
  888. return '<h' + level + '>' + text + '</h' + level + '>\n';
  889. };
  890. hr() {
  891. return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
  892. };
  893. list(body, ordered, start) {
  894. const type = ordered ? 'ol' : 'ul',
  895. startatt = (ordered && start !== 1) ? (' start="' + start + '"') : '';
  896. return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
  897. };
  898. listitem(text) {
  899. return '<li>' + text + '</li>\n';
  900. };
  901. checkbox(checked) {
  902. return '<input '
  903. + (checked ? 'checked="" ' : '')
  904. + 'disabled="" type="checkbox"'
  905. + (this.options.xhtml ? ' /' : '')
  906. + '> ';
  907. };
  908. paragraph(text) {
  909. return '<p>' + text + '</p>\n';
  910. };
  911. table(header, body) {
  912. if (body) body = '<tbody>' + body + '</tbody>';
  913. return '<table>\n'
  914. + '<thead>\n'
  915. + header
  916. + '</thead>\n'
  917. + body
  918. + '</table>\n';
  919. };
  920. tablerow(content) {
  921. return '<tr>\n' + content + '</tr>\n';
  922. };
  923. tablecell(content, flags) {
  924. const type = flags.header ? 'th' : 'td';
  925. const tag = flags.align
  926. ? '<' + type + ' align="' + flags.align + '">'
  927. : '<' + type + '>';
  928. return tag + content + '</' + type + '>\n';
  929. };
  930. // span level renderer
  931. strong(text) {
  932. return '<strong>' + text + '</strong>';
  933. };
  934. em(text) {
  935. return '<em>' + text + '</em>';
  936. };
  937. codespan(text) {
  938. return '<code>' + text + '</code>';
  939. };
  940. br() {
  941. return this.options.xhtml ? '<br/>' : '<br>';
  942. };
  943. del(text) {
  944. return '<del>' + text + '</del>';
  945. };
  946. link(href, title, text) {
  947. href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href);
  948. if (href === null) {
  949. return text;
  950. }
  951. let out = '<a href="' + escape$2(href) + '"';
  952. if (title) {
  953. out += ' title="' + title + '"';
  954. }
  955. out += '>' + text + '</a>';
  956. return out;
  957. };
  958. image(href, title, text) {
  959. href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href);
  960. if (href === null) {
  961. return text;
  962. }
  963. let out = '<img src="' + href + '" alt="' + text + '"';
  964. if (title) {
  965. out += ' title="' + title + '"';
  966. }
  967. out += this.options.xhtml ? '/>' : '>';
  968. return out;
  969. };
  970. text(text) {
  971. return text;
  972. };
  973. };
  974. /**
  975. * Slugger generates header id
  976. */
  977. var Slugger_1 = class Slugger {
  978. constructor() {
  979. this.seen = {};
  980. }
  981. /**
  982. * Convert string to unique id
  983. */
  984. slug(value) {
  985. let slug = value
  986. .toLowerCase()
  987. .trim()
  988. .replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '')
  989. .replace(/\s/g, '-');
  990. if (this.seen.hasOwnProperty(slug)) {
  991. const originalSlug = slug;
  992. do {
  993. this.seen[originalSlug]++;
  994. slug = originalSlug + '-' + this.seen[originalSlug];
  995. } while (this.seen.hasOwnProperty(slug));
  996. }
  997. this.seen[slug] = 0;
  998. return slug;
  999. };
  1000. };
  1001. const { defaults: defaults$3 } = defaults;
  1002. const { inline: inline$1 } = rules;
  1003. const {
  1004. findClosingBracket: findClosingBracket$1,
  1005. escape: escape$3
  1006. } = helpers;
  1007. /**
  1008. * Inline Lexer & Compiler
  1009. */
  1010. var InlineLexer_1 = class InlineLexer {
  1011. constructor(links, options) {
  1012. this.options = options || defaults$3;
  1013. this.links = links;
  1014. this.rules = inline$1.normal;
  1015. this.options.renderer = this.options.renderer || new Renderer_1();
  1016. this.renderer = this.options.renderer;
  1017. this.renderer.options = this.options;
  1018. if (!this.links) {
  1019. throw new Error('Tokens array requires a `links` property.');
  1020. }
  1021. if (this.options.pedantic) {
  1022. this.rules = inline$1.pedantic;
  1023. } else if (this.options.gfm) {
  1024. if (this.options.breaks) {
  1025. this.rules = inline$1.breaks;
  1026. } else {
  1027. this.rules = inline$1.gfm;
  1028. }
  1029. }
  1030. }
  1031. /**
  1032. * Expose Inline Rules
  1033. */
  1034. static get rules() {
  1035. return inline$1;
  1036. }
  1037. /**
  1038. * Static Lexing/Compiling Method
  1039. */
  1040. static output(src, links, options) {
  1041. const inline = new InlineLexer(links, options);
  1042. return inline.output(src);
  1043. }
  1044. /**
  1045. * Lexing/Compiling
  1046. */
  1047. output(src) {
  1048. let out = '',
  1049. link,
  1050. text,
  1051. href,
  1052. title,
  1053. cap,
  1054. prevCapZero;
  1055. while (src) {
  1056. // escape
  1057. if (cap = this.rules.escape.exec(src)) {
  1058. src = src.substring(cap[0].length);
  1059. out += escape$3(cap[1]);
  1060. continue;
  1061. }
  1062. // tag
  1063. if (cap = this.rules.tag.exec(src)) {
  1064. if (!this.inLink && /^<a /i.test(cap[0])) {
  1065. this.inLink = true;
  1066. } else if (this.inLink && /^<\/a>/i.test(cap[0])) {
  1067. this.inLink = false;
  1068. }
  1069. if (!this.inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
  1070. this.inRawBlock = true;
  1071. } else if (this.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
  1072. this.inRawBlock = false;
  1073. }
  1074. src = src.substring(cap[0].length);
  1075. out += this.renderer.html(this.options.sanitize
  1076. ? (this.options.sanitizer
  1077. ? this.options.sanitizer(cap[0])
  1078. : escape$3(cap[0]))
  1079. : cap[0]);
  1080. continue;
  1081. }
  1082. // link
  1083. if (cap = this.rules.link.exec(src)) {
  1084. const lastParenIndex = findClosingBracket$1(cap[2], '()');
  1085. if (lastParenIndex > -1) {
  1086. const start = cap[0].indexOf('!') === 0 ? 5 : 4;
  1087. const linkLen = start + cap[1].length + lastParenIndex;
  1088. cap[2] = cap[2].substring(0, lastParenIndex);
  1089. cap[0] = cap[0].substring(0, linkLen).trim();
  1090. cap[3] = '';
  1091. }
  1092. src = src.substring(cap[0].length);
  1093. this.inLink = true;
  1094. href = cap[2];
  1095. if (this.options.pedantic) {
  1096. link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href);
  1097. if (link) {
  1098. href = link[1];
  1099. title = link[3];
  1100. } else {
  1101. title = '';
  1102. }
  1103. } else {
  1104. title = cap[3] ? cap[3].slice(1, -1) : '';
  1105. }
  1106. href = href.trim().replace(/^<([\s\S]*)>$/, '$1');
  1107. out += this.outputLink(cap, {
  1108. href: InlineLexer.escapes(href),
  1109. title: InlineLexer.escapes(title)
  1110. });
  1111. this.inLink = false;
  1112. continue;
  1113. }
  1114. // reflink, nolink
  1115. if ((cap = this.rules.reflink.exec(src))
  1116. || (cap = this.rules.nolink.exec(src))) {
  1117. src = src.substring(cap[0].length);
  1118. link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
  1119. link = this.links[link.toLowerCase()];
  1120. if (!link || !link.href) {
  1121. out += cap[0].charAt(0);
  1122. src = cap[0].substring(1) + src;
  1123. continue;
  1124. }
  1125. this.inLink = true;
  1126. out += this.outputLink(cap, link);
  1127. this.inLink = false;
  1128. continue;
  1129. }
  1130. // strong
  1131. if (cap = this.rules.strong.exec(src)) {
  1132. src = src.substring(cap[0].length);
  1133. out += this.renderer.strong(this.output(cap[4] || cap[3] || cap[2] || cap[1]));
  1134. continue;
  1135. }
  1136. // em
  1137. if (cap = this.rules.em.exec(src)) {
  1138. src = src.substring(cap[0].length);
  1139. out += this.renderer.em(this.output(cap[6] || cap[5] || cap[4] || cap[3] || cap[2] || cap[1]));
  1140. continue;
  1141. }
  1142. // code
  1143. if (cap = this.rules.code.exec(src)) {
  1144. src = src.substring(cap[0].length);
  1145. out += this.renderer.codespan(escape$3(cap[2].trim(), true));
  1146. continue;
  1147. }
  1148. // br
  1149. if (cap = this.rules.br.exec(src)) {
  1150. src = src.substring(cap[0].length);
  1151. out += this.renderer.br();
  1152. continue;
  1153. }
  1154. // del (gfm)
  1155. if (cap = this.rules.del.exec(src)) {
  1156. src = src.substring(cap[0].length);
  1157. out += this.renderer.del(this.output(cap[1]));
  1158. continue;
  1159. }
  1160. // autolink
  1161. if (cap = this.rules.autolink.exec(src)) {
  1162. src = src.substring(cap[0].length);
  1163. if (cap[2] === '@') {
  1164. text = escape$3(this.mangle(cap[1]));
  1165. href = 'mailto:' + text;
  1166. } else {
  1167. text = escape$3(cap[1]);
  1168. href = text;
  1169. }
  1170. out += this.renderer.link(href, null, text);
  1171. continue;
  1172. }
  1173. // url (gfm)
  1174. if (!this.inLink && (cap = this.rules.url.exec(src))) {
  1175. if (cap[2] === '@') {
  1176. text = escape$3(cap[0]);
  1177. href = 'mailto:' + text;
  1178. } else {
  1179. // do extended autolink path validation
  1180. do {
  1181. prevCapZero = cap[0];
  1182. cap[0] = this.rules._backpedal.exec(cap[0])[0];
  1183. } while (prevCapZero !== cap[0]);
  1184. text = escape$3(cap[0]);
  1185. if (cap[1] === 'www.') {
  1186. href = 'http://' + text;
  1187. } else {
  1188. href = text;
  1189. }
  1190. }
  1191. src = src.substring(cap[0].length);
  1192. out += this.renderer.link(href, null, text);
  1193. continue;
  1194. }
  1195. // text
  1196. if (cap = this.rules.text.exec(src)) {
  1197. src = src.substring(cap[0].length);
  1198. if (this.inRawBlock) {
  1199. out += this.renderer.text(this.options.sanitize ? (this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$3(cap[0])) : cap[0]);
  1200. } else {
  1201. out += this.renderer.text(escape$3(this.smartypants(cap[0])));
  1202. }
  1203. continue;
  1204. }
  1205. if (src) {
  1206. throw new Error('Infinite loop on byte: ' + src.charCodeAt(0));
  1207. }
  1208. }
  1209. return out;
  1210. }
  1211. static escapes(text) {
  1212. return text ? text.replace(InlineLexer.rules._escapes, '$1') : text;
  1213. }
  1214. /**
  1215. * Compile Link
  1216. */
  1217. outputLink(cap, link) {
  1218. const href = link.href,
  1219. title = link.title ? escape$3(link.title) : null;
  1220. return cap[0].charAt(0) !== '!'
  1221. ? this.renderer.link(href, title, this.output(cap[1]))
  1222. : this.renderer.image(href, title, escape$3(cap[1]));
  1223. }
  1224. /**
  1225. * Smartypants Transformations
  1226. */
  1227. smartypants(text) {
  1228. if (!this.options.smartypants) return text;
  1229. return text
  1230. // em-dashes
  1231. .replace(/---/g, '\u2014')
  1232. // en-dashes
  1233. .replace(/--/g, '\u2013')
  1234. // opening singles
  1235. .replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
  1236. // closing singles & apostrophes
  1237. .replace(/'/g, '\u2019')
  1238. // opening doubles
  1239. .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
  1240. // closing doubles
  1241. .replace(/"/g, '\u201d')
  1242. // ellipses
  1243. .replace(/\.{3}/g, '\u2026');
  1244. }
  1245. /**
  1246. * Mangle Links
  1247. */
  1248. mangle(text) {
  1249. if (!this.options.mangle) return text;
  1250. const l = text.length;
  1251. let out = '',
  1252. i = 0,
  1253. ch;
  1254. for (; i < l; i++) {
  1255. ch = text.charCodeAt(i);
  1256. if (Math.random() > 0.5) {
  1257. ch = 'x' + ch.toString(16);
  1258. }
  1259. out += '&#' + ch + ';';
  1260. }
  1261. return out;
  1262. }
  1263. };
  1264. /**
  1265. * TextRenderer
  1266. * returns only the textual part of the token
  1267. */
  1268. var TextRenderer_1 = class TextRenderer {
  1269. // no need for block level renderers
  1270. strong(text) {
  1271. return text;
  1272. }
  1273. em(text) {
  1274. return text;
  1275. }
  1276. codespan(text) {
  1277. return text;
  1278. }
  1279. del(text) {
  1280. return text;
  1281. }
  1282. text(text) {
  1283. return text;
  1284. }
  1285. link(href, title, text) {
  1286. return '' + text;
  1287. }
  1288. image(href, title, text) {
  1289. return '' + text;
  1290. }
  1291. br() {
  1292. return '';
  1293. }
  1294. };
  1295. const { defaults: defaults$4 } = defaults;
  1296. const {
  1297. merge: merge$2,
  1298. unescape: unescape$1
  1299. } = helpers;
  1300. /**
  1301. * Parsing & Compiling
  1302. */
  1303. var Parser_1 = class Parser {
  1304. constructor(options) {
  1305. this.tokens = [];
  1306. this.token = null;
  1307. this.options = options || defaults$4;
  1308. this.options.renderer = this.options.renderer || new Renderer_1();
  1309. this.renderer = this.options.renderer;
  1310. this.renderer.options = this.options;
  1311. this.slugger = new Slugger_1();
  1312. }
  1313. /**
  1314. * Static Parse Method
  1315. */
  1316. static parse(tokens, options) {
  1317. const parser = new Parser(options);
  1318. return parser.parse(tokens);
  1319. };
  1320. /**
  1321. * Parse Loop
  1322. */
  1323. parse(tokens) {
  1324. this.inline = new InlineLexer_1(tokens.links, this.options);
  1325. // use an InlineLexer with a TextRenderer to extract pure text
  1326. this.inlineText = new InlineLexer_1(
  1327. tokens.links,
  1328. merge$2({}, this.options, { renderer: new TextRenderer_1() })
  1329. );
  1330. this.tokens = tokens.reverse();
  1331. let out = '';
  1332. while (this.next()) {
  1333. out += this.tok();
  1334. }
  1335. return out;
  1336. };
  1337. /**
  1338. * Next Token
  1339. */
  1340. next() {
  1341. this.token = this.tokens.pop();
  1342. return this.token;
  1343. };
  1344. /**
  1345. * Preview Next Token
  1346. */
  1347. peek() {
  1348. return this.tokens[this.tokens.length - 1] || 0;
  1349. };
  1350. /**
  1351. * Parse Text Tokens
  1352. */
  1353. parseText() {
  1354. let body = this.token.text;
  1355. while (this.peek().type === 'text') {
  1356. body += '\n' + this.next().text;
  1357. }
  1358. return this.inline.output(body);
  1359. };
  1360. /**
  1361. * Parse Current Token
  1362. */
  1363. tok() {
  1364. let body = '';
  1365. switch (this.token.type) {
  1366. case 'space': {
  1367. return '';
  1368. }
  1369. case 'hr': {
  1370. return this.renderer.hr();
  1371. }
  1372. case 'heading': {
  1373. return this.renderer.heading(
  1374. this.inline.output(this.token.text),
  1375. this.token.depth,
  1376. unescape$1(this.inlineText.output(this.token.text)),
  1377. this.slugger);
  1378. }
  1379. case 'code': {
  1380. return this.renderer.code(this.token.text,
  1381. this.token.lang,
  1382. this.token.escaped);
  1383. }
  1384. case 'table': {
  1385. let header = '',
  1386. i,
  1387. row,
  1388. cell,
  1389. j;
  1390. // header
  1391. cell = '';
  1392. for (i = 0; i < this.token.header.length; i++) {
  1393. cell += this.renderer.tablecell(
  1394. this.inline.output(this.token.header[i]),
  1395. { header: true, align: this.token.align[i] }
  1396. );
  1397. }
  1398. header += this.renderer.tablerow(cell);
  1399. for (i = 0; i < this.token.cells.length; i++) {
  1400. row = this.token.cells[i];
  1401. cell = '';
  1402. for (j = 0; j < row.length; j++) {
  1403. cell += this.renderer.tablecell(
  1404. this.inline.output(row[j]),
  1405. { header: false, align: this.token.align[j] }
  1406. );
  1407. }
  1408. body += this.renderer.tablerow(cell);
  1409. }
  1410. return this.renderer.table(header, body);
  1411. }
  1412. case 'blockquote_start': {
  1413. body = '';
  1414. while (this.next().type !== 'blockquote_end') {
  1415. body += this.tok();
  1416. }
  1417. return this.renderer.blockquote(body);
  1418. }
  1419. case 'list_start': {
  1420. body = '';
  1421. const ordered = this.token.ordered,
  1422. start = this.token.start;
  1423. while (this.next().type !== 'list_end') {
  1424. body += this.tok();
  1425. }
  1426. return this.renderer.list(body, ordered, start);
  1427. }
  1428. case 'list_item_start': {
  1429. body = '';
  1430. const loose = this.token.loose;
  1431. const checked = this.token.checked;
  1432. const task = this.token.task;
  1433. if (this.token.task) {
  1434. if (loose) {
  1435. if (this.peek().type === 'text') {
  1436. const nextToken = this.peek();
  1437. nextToken.text = this.renderer.checkbox(checked) + ' ' + nextToken.text;
  1438. } else {
  1439. this.tokens.push({
  1440. type: 'text',
  1441. text: this.renderer.checkbox(checked)
  1442. });
  1443. }
  1444. } else {
  1445. body += this.renderer.checkbox(checked);
  1446. }
  1447. }
  1448. while (this.next().type !== 'list_item_end') {
  1449. body += !loose && this.token.type === 'text'
  1450. ? this.parseText()
  1451. : this.tok();
  1452. }
  1453. return this.renderer.listitem(body, task, checked);
  1454. }
  1455. case 'html': {
  1456. // TODO parse inline content if parameter markdown=1
  1457. return this.renderer.html(this.token.text);
  1458. }
  1459. case 'paragraph': {
  1460. return this.renderer.paragraph(this.inline.output(this.token.text));
  1461. }
  1462. case 'text': {
  1463. return this.renderer.paragraph(this.parseText());
  1464. }
  1465. default: {
  1466. const errMsg = 'Token with "' + this.token.type + '" type was not found.';
  1467. if (this.options.silent) {
  1468. console.log(errMsg);
  1469. } else {
  1470. throw new Error(errMsg);
  1471. }
  1472. }
  1473. }
  1474. };
  1475. };
  1476. const {
  1477. merge: merge$3,
  1478. checkSanitizeDeprecation: checkSanitizeDeprecation$1,
  1479. escape: escape$4
  1480. } = helpers;
  1481. const {
  1482. getDefaults,
  1483. changeDefaults,
  1484. defaults: defaults$5
  1485. } = defaults;
  1486. /**
  1487. * Marked
  1488. */
  1489. function marked(src, opt, callback) {
  1490. // throw error in case of non string input
  1491. if (typeof src === 'undefined' || src === null) {
  1492. throw new Error('marked(): input parameter is undefined or null');
  1493. }
  1494. if (typeof src !== 'string') {
  1495. throw new Error('marked(): input parameter is of type '
  1496. + Object.prototype.toString.call(src) + ', string expected');
  1497. }
  1498. if (callback || typeof opt === 'function') {
  1499. if (!callback) {
  1500. callback = opt;
  1501. opt = null;
  1502. }
  1503. opt = merge$3({}, marked.defaults, opt || {});
  1504. checkSanitizeDeprecation$1(opt);
  1505. const highlight = opt.highlight;
  1506. let tokens,
  1507. pending,
  1508. i = 0;
  1509. try {
  1510. tokens = Lexer_1.lex(src, opt);
  1511. } catch (e) {
  1512. return callback(e);
  1513. }
  1514. pending = tokens.length;
  1515. const done = function(err) {
  1516. if (err) {
  1517. opt.highlight = highlight;
  1518. return callback(err);
  1519. }
  1520. let out;
  1521. try {
  1522. out = Parser_1.parse(tokens, opt);
  1523. } catch (e) {
  1524. err = e;
  1525. }
  1526. opt.highlight = highlight;
  1527. return err
  1528. ? callback(err)
  1529. : callback(null, out);
  1530. };
  1531. if (!highlight || highlight.length < 3) {
  1532. return done();
  1533. }
  1534. delete opt.highlight;
  1535. if (!pending) return done();
  1536. for (; i < tokens.length; i++) {
  1537. (function(token) {
  1538. if (token.type !== 'code') {
  1539. return --pending || done();
  1540. }
  1541. return highlight(token.text, token.lang, function(err, code) {
  1542. if (err) return done(err);
  1543. if (code == null || code === token.text) {
  1544. return --pending || done();
  1545. }
  1546. token.text = code;
  1547. token.escaped = true;
  1548. --pending || done();
  1549. });
  1550. })(tokens[i]);
  1551. }
  1552. return;
  1553. }
  1554. try {
  1555. opt = merge$3({}, marked.defaults, opt || {});
  1556. checkSanitizeDeprecation$1(opt);
  1557. return Parser_1.parse(Lexer_1.lex(src, opt), opt);
  1558. } catch (e) {
  1559. e.message += '\nPlease report this to https://github.com/markedjs/marked.';
  1560. if ((opt || marked.defaults).silent) {
  1561. return '<p>An error occurred:</p><pre>'
  1562. + escape$4(e.message + '', true)
  1563. + '</pre>';
  1564. }
  1565. throw e;
  1566. }
  1567. }
  1568. /**
  1569. * Options
  1570. */
  1571. marked.options =
  1572. marked.setOptions = function(opt) {
  1573. merge$3(marked.defaults, opt);
  1574. changeDefaults(marked.defaults);
  1575. return marked;
  1576. };
  1577. marked.getDefaults = getDefaults;
  1578. marked.defaults = defaults$5;
  1579. /**
  1580. * Expose
  1581. */
  1582. marked.Parser = Parser_1;
  1583. marked.parser = Parser_1.parse;
  1584. marked.Renderer = Renderer_1;
  1585. marked.TextRenderer = TextRenderer_1;
  1586. marked.Lexer = Lexer_1;
  1587. marked.lexer = Lexer_1.lex;
  1588. marked.InlineLexer = InlineLexer_1;
  1589. marked.inlineLexer = InlineLexer_1.output;
  1590. marked.Slugger = Slugger_1;
  1591. marked.parse = marked;
  1592. var marked_1 = marked;
  1593. export default marked_1;