marked.js 67 KB

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