marked.esm.js 55 KB

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