marked.js 51 KB

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