marked.js 76 KB

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