marked.js 73 KB

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