marked.js 63 KB

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