marked.js 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779
  1. /**
  2. * marked - a markdown parser
  3. * Copyright (c) 2011-2021, Christopher Jeffrey. (MIT Licensed)
  4. * https://github.com/markedjs/marked
  5. */
  6. /**
  7. * DO NOT EDIT THIS FILE
  8. * The code in this file is generated from files in ./src/
  9. */
  10. (function (global, factory) {
  11. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  12. typeof define === 'function' && define.amd ? define(factory) :
  13. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.marked = factory());
  14. }(this, (function () { 'use strict';
  15. function _defineProperties(target, props) {
  16. for (var i = 0; i < props.length; i++) {
  17. var descriptor = props[i];
  18. descriptor.enumerable = descriptor.enumerable || false;
  19. descriptor.configurable = true;
  20. if ("value" in descriptor) descriptor.writable = true;
  21. Object.defineProperty(target, descriptor.key, descriptor);
  22. }
  23. }
  24. function _createClass(Constructor, protoProps, staticProps) {
  25. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  26. if (staticProps) _defineProperties(Constructor, staticProps);
  27. return Constructor;
  28. }
  29. function _unsupportedIterableToArray(o, minLen) {
  30. if (!o) return;
  31. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  32. var n = Object.prototype.toString.call(o).slice(8, -1);
  33. if (n === "Object" && o.constructor) n = o.constructor.name;
  34. if (n === "Map" || n === "Set") return Array.from(o);
  35. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  36. }
  37. function _arrayLikeToArray(arr, len) {
  38. if (len == null || len > arr.length) len = arr.length;
  39. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  40. return arr2;
  41. }
  42. function _createForOfIteratorHelperLoose(o, allowArrayLike) {
  43. var it;
  44. if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
  45. if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
  46. if (it) o = it;
  47. var i = 0;
  48. return function () {
  49. if (i >= o.length) return {
  50. done: true
  51. };
  52. return {
  53. done: false,
  54. value: o[i++]
  55. };
  56. };
  57. }
  58. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  59. }
  60. it = o[Symbol.iterator]();
  61. return it.next.bind(it);
  62. }
  63. function createCommonjsModule(fn) {
  64. var module = { exports: {} };
  65. return fn(module, module.exports), module.exports;
  66. }
  67. var defaults = createCommonjsModule(function (module) {
  68. function getDefaults() {
  69. return {
  70. baseUrl: null,
  71. breaks: false,
  72. gfm: true,
  73. headerIds: true,
  74. headerPrefix: '',
  75. highlight: null,
  76. langPrefix: 'language-',
  77. mangle: true,
  78. pedantic: false,
  79. renderer: null,
  80. sanitize: false,
  81. sanitizer: null,
  82. silent: false,
  83. smartLists: false,
  84. smartypants: false,
  85. tokenizer: null,
  86. walkTokens: null,
  87. xhtml: false
  88. };
  89. }
  90. function changeDefaults(newDefaults) {
  91. module.exports.defaults = newDefaults;
  92. }
  93. module.exports = {
  94. defaults: getDefaults(),
  95. getDefaults: getDefaults,
  96. changeDefaults: changeDefaults
  97. };
  98. });
  99. /**
  100. * Helpers
  101. */
  102. var escapeTest = /[&<>"']/;
  103. var escapeReplace = /[&<>"']/g;
  104. var escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/;
  105. var escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g;
  106. var escapeReplacements = {
  107. '&': '&amp;',
  108. '<': '&lt;',
  109. '>': '&gt;',
  110. '"': '&quot;',
  111. "'": '&#39;'
  112. };
  113. var getEscapeReplacement = function getEscapeReplacement(ch) {
  114. return escapeReplacements[ch];
  115. };
  116. function escape(html, encode) {
  117. if (encode) {
  118. if (escapeTest.test(html)) {
  119. return html.replace(escapeReplace, getEscapeReplacement);
  120. }
  121. } else {
  122. if (escapeTestNoEncode.test(html)) {
  123. return html.replace(escapeReplaceNoEncode, getEscapeReplacement);
  124. }
  125. }
  126. return html;
  127. }
  128. var unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
  129. function unescape(html) {
  130. // explicitly match decimal, hex, and named HTML entities
  131. return html.replace(unescapeTest, function (_, n) {
  132. n = n.toLowerCase();
  133. if (n === 'colon') return ':';
  134. if (n.charAt(0) === '#') {
  135. return n.charAt(1) === 'x' ? String.fromCharCode(parseInt(n.substring(2), 16)) : String.fromCharCode(+n.substring(1));
  136. }
  137. return '';
  138. });
  139. }
  140. var caret = /(^|[^\[])\^/g;
  141. function edit(regex, opt) {
  142. regex = regex.source || regex;
  143. opt = opt || '';
  144. var obj = {
  145. replace: function replace(name, val) {
  146. val = val.source || val;
  147. val = val.replace(caret, '$1');
  148. regex = regex.replace(name, val);
  149. return obj;
  150. },
  151. getRegex: function getRegex() {
  152. return new RegExp(regex, opt);
  153. }
  154. };
  155. return obj;
  156. }
  157. var nonWordAndColonTest = /[^\w:]/g;
  158. var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
  159. function cleanUrl(sanitize, base, href) {
  160. if (sanitize) {
  161. var prot;
  162. try {
  163. prot = decodeURIComponent(unescape(href)).replace(nonWordAndColonTest, '').toLowerCase();
  164. } catch (e) {
  165. return null;
  166. }
  167. if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
  168. return null;
  169. }
  170. }
  171. if (base && !originIndependentUrl.test(href)) {
  172. href = resolveUrl(base, href);
  173. }
  174. try {
  175. href = encodeURI(href).replace(/%25/g, '%');
  176. } catch (e) {
  177. return null;
  178. }
  179. return href;
  180. }
  181. var baseUrls = {};
  182. var justDomain = /^[^:]+:\/*[^/]*$/;
  183. var protocol = /^([^:]+:)[\s\S]*$/;
  184. var domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
  185. function resolveUrl(base, href) {
  186. if (!baseUrls[' ' + base]) {
  187. // we can ignore everything in base after the last slash of its path component,
  188. // but we might need to add _that_
  189. // https://tools.ietf.org/html/rfc3986#section-3
  190. if (justDomain.test(base)) {
  191. baseUrls[' ' + base] = base + '/';
  192. } else {
  193. baseUrls[' ' + base] = rtrim(base, '/', true);
  194. }
  195. }
  196. base = baseUrls[' ' + base];
  197. var relativeBase = base.indexOf(':') === -1;
  198. if (href.substring(0, 2) === '//') {
  199. if (relativeBase) {
  200. return href;
  201. }
  202. return base.replace(protocol, '$1') + href;
  203. } else if (href.charAt(0) === '/') {
  204. if (relativeBase) {
  205. return href;
  206. }
  207. return base.replace(domain, '$1') + href;
  208. } else {
  209. return base + href;
  210. }
  211. }
  212. var noopTest = {
  213. exec: function noopTest() {}
  214. };
  215. function merge(obj) {
  216. var i = 1,
  217. target,
  218. key;
  219. for (; i < arguments.length; i++) {
  220. target = arguments[i];
  221. for (key in target) {
  222. if (Object.prototype.hasOwnProperty.call(target, key)) {
  223. obj[key] = target[key];
  224. }
  225. }
  226. }
  227. return obj;
  228. }
  229. function splitCells(tableRow, count) {
  230. // ensure that every cell-delimiting pipe has a space
  231. // before it to distinguish it from an escaped pipe
  232. var row = tableRow.replace(/\|/g, function (match, offset, str) {
  233. var escaped = false,
  234. curr = offset;
  235. while (--curr >= 0 && str[curr] === '\\') {
  236. escaped = !escaped;
  237. }
  238. if (escaped) {
  239. // odd number of slashes means | is escaped
  240. // so we leave it alone
  241. return '|';
  242. } else {
  243. // add space before unescaped |
  244. return ' |';
  245. }
  246. }),
  247. cells = row.split(/ \|/);
  248. var i = 0;
  249. if (cells.length > count) {
  250. cells.splice(count);
  251. } else {
  252. while (cells.length < count) {
  253. cells.push('');
  254. }
  255. }
  256. for (; i < cells.length; i++) {
  257. // leading or trailing whitespace is ignored per the gfm spec
  258. cells[i] = cells[i].trim().replace(/\\\|/g, '|');
  259. }
  260. return cells;
  261. } // Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
  262. // /c*$/ is vulnerable to REDOS.
  263. // invert: Remove suffix of non-c chars instead. Default falsey.
  264. function rtrim(str, c, invert) {
  265. var l = str.length;
  266. if (l === 0) {
  267. return '';
  268. } // Length of suffix matching the invert condition.
  269. var suffLen = 0; // Step left until we fail to match the invert condition.
  270. while (suffLen < l) {
  271. var currChar = str.charAt(l - suffLen - 1);
  272. if (currChar === c && !invert) {
  273. suffLen++;
  274. } else if (currChar !== c && invert) {
  275. suffLen++;
  276. } else {
  277. break;
  278. }
  279. }
  280. return str.substr(0, l - suffLen);
  281. }
  282. function findClosingBracket(str, b) {
  283. if (str.indexOf(b[1]) === -1) {
  284. return -1;
  285. }
  286. var l = str.length;
  287. var level = 0,
  288. i = 0;
  289. for (; i < l; i++) {
  290. if (str[i] === '\\') {
  291. i++;
  292. } else if (str[i] === b[0]) {
  293. level++;
  294. } else if (str[i] === b[1]) {
  295. level--;
  296. if (level < 0) {
  297. return i;
  298. }
  299. }
  300. }
  301. return -1;
  302. }
  303. function checkSanitizeDeprecation(opt) {
  304. if (opt && opt.sanitize && !opt.silent) {
  305. console.warn('marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options');
  306. }
  307. } // copied from https://stackoverflow.com/a/5450113/806777
  308. function repeatString(pattern, count) {
  309. if (count < 1) {
  310. return '';
  311. }
  312. var result = '';
  313. while (count > 1) {
  314. if (count & 1) {
  315. result += pattern;
  316. }
  317. count >>= 1;
  318. pattern += pattern;
  319. }
  320. return result + pattern;
  321. }
  322. var helpers = {
  323. escape: escape,
  324. unescape: unescape,
  325. edit: edit,
  326. cleanUrl: cleanUrl,
  327. resolveUrl: resolveUrl,
  328. noopTest: noopTest,
  329. merge: merge,
  330. splitCells: splitCells,
  331. rtrim: rtrim,
  332. findClosingBracket: findClosingBracket,
  333. checkSanitizeDeprecation: checkSanitizeDeprecation,
  334. repeatString: repeatString
  335. };
  336. var defaults$1 = defaults.defaults;
  337. var rtrim$1 = helpers.rtrim,
  338. splitCells$1 = helpers.splitCells,
  339. _escape = helpers.escape,
  340. findClosingBracket$1 = helpers.findClosingBracket;
  341. function outputLink(cap, link, raw) {
  342. var href = link.href;
  343. var title = link.title ? _escape(link.title) : null;
  344. var text = cap[1].replace(/\\([\[\]])/g, '$1');
  345. if (cap[0].charAt(0) !== '!') {
  346. return {
  347. type: 'link',
  348. raw: raw,
  349. href: href,
  350. title: title,
  351. text: text
  352. };
  353. } else {
  354. return {
  355. type: 'image',
  356. raw: raw,
  357. href: href,
  358. title: title,
  359. text: _escape(text)
  360. };
  361. }
  362. }
  363. function indentCodeCompensation(raw, text) {
  364. var matchIndentToCode = raw.match(/^(\s+)(?:```)/);
  365. if (matchIndentToCode === null) {
  366. return text;
  367. }
  368. var indentToCode = matchIndentToCode[1];
  369. return text.split('\n').map(function (node) {
  370. var matchIndentInNode = node.match(/^\s+/);
  371. if (matchIndentInNode === null) {
  372. return node;
  373. }
  374. var indentInNode = matchIndentInNode[0];
  375. if (indentInNode.length >= indentToCode.length) {
  376. return node.slice(indentToCode.length);
  377. }
  378. return node;
  379. }).join('\n');
  380. }
  381. /**
  382. * Tokenizer
  383. */
  384. var Tokenizer_1 = /*#__PURE__*/function () {
  385. function Tokenizer(options) {
  386. this.options = options || defaults$1;
  387. }
  388. var _proto = Tokenizer.prototype;
  389. _proto.space = function space(src) {
  390. var cap = this.rules.block.newline.exec(src);
  391. if (cap) {
  392. if (cap[0].length > 1) {
  393. return {
  394. type: 'space',
  395. raw: cap[0]
  396. };
  397. }
  398. return {
  399. raw: '\n'
  400. };
  401. }
  402. };
  403. _proto.code = function code(src) {
  404. var cap = this.rules.block.code.exec(src);
  405. if (cap) {
  406. var text = cap[0].replace(/^ {1,4}/gm, '');
  407. return {
  408. type: 'code',
  409. raw: cap[0],
  410. codeBlockStyle: 'indented',
  411. text: !this.options.pedantic ? rtrim$1(text, '\n') : text
  412. };
  413. }
  414. };
  415. _proto.fences = function fences(src) {
  416. var cap = this.rules.block.fences.exec(src);
  417. if (cap) {
  418. var raw = cap[0];
  419. var text = indentCodeCompensation(raw, cap[3] || '');
  420. return {
  421. type: 'code',
  422. raw: raw,
  423. lang: cap[2] ? cap[2].trim() : cap[2],
  424. text: text
  425. };
  426. }
  427. };
  428. _proto.heading = function heading(src) {
  429. var cap = this.rules.block.heading.exec(src);
  430. if (cap) {
  431. var text = cap[2].trim(); // remove trailing #s
  432. if (/#$/.test(text)) {
  433. var trimmed = rtrim$1(text, '#');
  434. if (this.options.pedantic) {
  435. text = trimmed.trim();
  436. } else if (!trimmed || / $/.test(trimmed)) {
  437. // CommonMark requires space before trailing #s
  438. text = trimmed.trim();
  439. }
  440. }
  441. return {
  442. type: 'heading',
  443. raw: cap[0],
  444. depth: cap[1].length,
  445. text: text
  446. };
  447. }
  448. };
  449. _proto.nptable = function nptable(src) {
  450. var cap = this.rules.block.nptable.exec(src);
  451. if (cap) {
  452. var item = {
  453. type: 'table',
  454. header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')),
  455. align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
  456. cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [],
  457. raw: cap[0]
  458. };
  459. if (item.header.length === item.align.length) {
  460. var l = item.align.length;
  461. var i;
  462. for (i = 0; i < l; i++) {
  463. if (/^ *-+: *$/.test(item.align[i])) {
  464. item.align[i] = 'right';
  465. } else if (/^ *:-+: *$/.test(item.align[i])) {
  466. item.align[i] = 'center';
  467. } else if (/^ *:-+ *$/.test(item.align[i])) {
  468. item.align[i] = 'left';
  469. } else {
  470. item.align[i] = null;
  471. }
  472. }
  473. l = item.cells.length;
  474. for (i = 0; i < l; i++) {
  475. item.cells[i] = splitCells$1(item.cells[i], item.header.length);
  476. }
  477. return item;
  478. }
  479. }
  480. };
  481. _proto.hr = function hr(src) {
  482. var cap = this.rules.block.hr.exec(src);
  483. if (cap) {
  484. return {
  485. type: 'hr',
  486. raw: cap[0]
  487. };
  488. }
  489. };
  490. _proto.blockquote = function blockquote(src) {
  491. var cap = this.rules.block.blockquote.exec(src);
  492. if (cap) {
  493. var text = cap[0].replace(/^ *> ?/gm, '');
  494. return {
  495. type: 'blockquote',
  496. raw: cap[0],
  497. text: text
  498. };
  499. }
  500. };
  501. _proto.list = function list(src) {
  502. var cap = this.rules.block.list.exec(src);
  503. if (cap) {
  504. var raw = cap[0];
  505. var bull = cap[2];
  506. var isordered = bull.length > 1;
  507. var list = {
  508. type: 'list',
  509. raw: raw,
  510. ordered: isordered,
  511. start: isordered ? +bull.slice(0, -1) : '',
  512. loose: false,
  513. items: []
  514. }; // Get each top-level item.
  515. var itemMatch = cap[0].match(this.rules.block.item);
  516. var next = false,
  517. item,
  518. space,
  519. bcurr,
  520. bnext,
  521. addBack,
  522. loose,
  523. istask,
  524. ischecked,
  525. endMatch;
  526. var l = itemMatch.length;
  527. bcurr = this.rules.block.listItemStart.exec(itemMatch[0]);
  528. for (var i = 0; i < l; i++) {
  529. item = itemMatch[i];
  530. raw = item;
  531. if (!this.options.pedantic) {
  532. // Determine if current item contains the end of the list
  533. endMatch = item.match(new RegExp('\\n\\s*\\n {0,' + (bcurr[0].length - 1) + '}\\S'));
  534. if (endMatch) {
  535. addBack = item.length - endMatch.index + itemMatch.slice(i + 1).join('\n').length;
  536. list.raw = list.raw.substring(0, list.raw.length - addBack);
  537. item = item.substring(0, endMatch.index);
  538. raw = item;
  539. l = i + 1;
  540. }
  541. } // Determine whether the next list item belongs here.
  542. // Backpedal if it does not belong in this list.
  543. if (i !== l - 1) {
  544. bnext = this.rules.block.listItemStart.exec(itemMatch[i + 1]);
  545. if (!this.options.pedantic ? bnext[1].length >= bcurr[0].length || bnext[1].length > 3 : bnext[1].length > bcurr[1].length) {
  546. // nested list or continuation
  547. itemMatch.splice(i, 2, itemMatch[i] + (!this.options.pedantic && bnext[1].length < bcurr[0].length && !itemMatch[i].match(/\n$/) ? '' : '\n') + itemMatch[i + 1]);
  548. i--;
  549. l--;
  550. continue;
  551. } else if ( // different bullet style
  552. !this.options.pedantic || this.options.smartLists ? bnext[2][bnext[2].length - 1] !== bull[bull.length - 1] : isordered === (bnext[2].length === 1)) {
  553. addBack = itemMatch.slice(i + 1).join('\n').length;
  554. list.raw = list.raw.substring(0, list.raw.length - addBack);
  555. i = l - 1;
  556. }
  557. bcurr = bnext;
  558. } // Remove the list item's bullet
  559. // so it is seen as the next token.
  560. space = item.length;
  561. item = item.replace(/^ *([*+-]|\d+[.)]) ?/, ''); // Outdent whatever the
  562. // list item contains. Hacky.
  563. if (~item.indexOf('\n ')) {
  564. space -= item.length;
  565. item = !this.options.pedantic ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') : item.replace(/^ {1,4}/gm, '');
  566. } // trim item newlines at end
  567. item = rtrim$1(item, '\n');
  568. if (i !== l - 1) {
  569. raw = raw + '\n';
  570. } // Determine whether item is loose or not.
  571. // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
  572. // for discount behavior.
  573. loose = next || /\n\n(?!\s*$)/.test(raw);
  574. if (i !== l - 1) {
  575. next = raw.slice(-2) === '\n\n';
  576. if (!loose) loose = next;
  577. }
  578. if (loose) {
  579. list.loose = true;
  580. } // Check for task list items
  581. if (this.options.gfm) {
  582. istask = /^\[[ xX]\] /.test(item);
  583. ischecked = undefined;
  584. if (istask) {
  585. ischecked = item[1] !== ' ';
  586. item = item.replace(/^\[[ xX]\] +/, '');
  587. }
  588. }
  589. list.items.push({
  590. type: 'list_item',
  591. raw: raw,
  592. task: istask,
  593. checked: ischecked,
  594. loose: loose,
  595. text: item
  596. });
  597. }
  598. return list;
  599. }
  600. };
  601. _proto.html = function html(src) {
  602. var cap = this.rules.block.html.exec(src);
  603. if (cap) {
  604. return {
  605. type: this.options.sanitize ? 'paragraph' : 'html',
  606. raw: cap[0],
  607. pre: !this.options.sanitizer && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
  608. text: this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : _escape(cap[0]) : cap[0]
  609. };
  610. }
  611. };
  612. _proto.def = function def(src) {
  613. var cap = this.rules.block.def.exec(src);
  614. if (cap) {
  615. if (cap[3]) cap[3] = cap[3].substring(1, cap[3].length - 1);
  616. var tag = cap[1].toLowerCase().replace(/\s+/g, ' ');
  617. return {
  618. tag: tag,
  619. raw: cap[0],
  620. href: cap[2],
  621. title: cap[3]
  622. };
  623. }
  624. };
  625. _proto.table = function table(src) {
  626. var cap = this.rules.block.table.exec(src);
  627. if (cap) {
  628. var item = {
  629. type: 'table',
  630. header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')),
  631. align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
  632. cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
  633. };
  634. if (item.header.length === item.align.length) {
  635. item.raw = cap[0];
  636. var l = item.align.length;
  637. var i;
  638. for (i = 0; i < l; i++) {
  639. if (/^ *-+: *$/.test(item.align[i])) {
  640. item.align[i] = 'right';
  641. } else if (/^ *:-+: *$/.test(item.align[i])) {
  642. item.align[i] = 'center';
  643. } else if (/^ *:-+ *$/.test(item.align[i])) {
  644. item.align[i] = 'left';
  645. } else {
  646. item.align[i] = null;
  647. }
  648. }
  649. l = item.cells.length;
  650. for (i = 0; i < l; i++) {
  651. item.cells[i] = splitCells$1(item.cells[i].replace(/^ *\| *| *\| *$/g, ''), item.header.length);
  652. }
  653. return item;
  654. }
  655. }
  656. };
  657. _proto.lheading = function lheading(src) {
  658. var cap = this.rules.block.lheading.exec(src);
  659. if (cap) {
  660. return {
  661. type: 'heading',
  662. raw: cap[0],
  663. depth: cap[2].charAt(0) === '=' ? 1 : 2,
  664. text: cap[1]
  665. };
  666. }
  667. };
  668. _proto.paragraph = function paragraph(src) {
  669. var cap = this.rules.block.paragraph.exec(src);
  670. if (cap) {
  671. return {
  672. type: 'paragraph',
  673. raw: cap[0],
  674. text: cap[1].charAt(cap[1].length - 1) === '\n' ? cap[1].slice(0, -1) : cap[1]
  675. };
  676. }
  677. };
  678. _proto.text = function text(src) {
  679. var cap = this.rules.block.text.exec(src);
  680. if (cap) {
  681. return {
  682. type: 'text',
  683. raw: cap[0],
  684. text: cap[0]
  685. };
  686. }
  687. };
  688. _proto.escape = function escape(src) {
  689. var cap = this.rules.inline.escape.exec(src);
  690. if (cap) {
  691. return {
  692. type: 'escape',
  693. raw: cap[0],
  694. text: _escape(cap[1])
  695. };
  696. }
  697. };
  698. _proto.tag = function tag(src, inLink, inRawBlock) {
  699. var cap = this.rules.inline.tag.exec(src);
  700. if (cap) {
  701. if (!inLink && /^<a /i.test(cap[0])) {
  702. inLink = true;
  703. } else if (inLink && /^<\/a>/i.test(cap[0])) {
  704. inLink = false;
  705. }
  706. if (!inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
  707. inRawBlock = true;
  708. } else if (inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
  709. inRawBlock = false;
  710. }
  711. return {
  712. type: this.options.sanitize ? 'text' : 'html',
  713. raw: cap[0],
  714. inLink: inLink,
  715. inRawBlock: inRawBlock,
  716. text: this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : _escape(cap[0]) : cap[0]
  717. };
  718. }
  719. };
  720. _proto.link = function link(src) {
  721. var cap = this.rules.inline.link.exec(src);
  722. if (cap) {
  723. var trimmedUrl = cap[2].trim();
  724. if (!this.options.pedantic && /^</.test(trimmedUrl)) {
  725. // commonmark requires matching angle brackets
  726. if (!/>$/.test(trimmedUrl)) {
  727. return;
  728. } // ending angle bracket cannot be escaped
  729. var rtrimSlash = rtrim$1(trimmedUrl.slice(0, -1), '\\');
  730. if ((trimmedUrl.length - rtrimSlash.length) % 2 === 0) {
  731. return;
  732. }
  733. } else {
  734. // find closing parenthesis
  735. var lastParenIndex = findClosingBracket$1(cap[2], '()');
  736. if (lastParenIndex > -1) {
  737. var start = cap[0].indexOf('!') === 0 ? 5 : 4;
  738. var linkLen = start + cap[1].length + lastParenIndex;
  739. cap[2] = cap[2].substring(0, lastParenIndex);
  740. cap[0] = cap[0].substring(0, linkLen).trim();
  741. cap[3] = '';
  742. }
  743. }
  744. var href = cap[2];
  745. var title = '';
  746. if (this.options.pedantic) {
  747. // split pedantic href and title
  748. var link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href);
  749. if (link) {
  750. href = link[1];
  751. title = link[3];
  752. }
  753. } else {
  754. title = cap[3] ? cap[3].slice(1, -1) : '';
  755. }
  756. href = href.trim();
  757. if (/^</.test(href)) {
  758. if (this.options.pedantic && !/>$/.test(trimmedUrl)) {
  759. // pedantic allows starting angle bracket without ending angle bracket
  760. href = href.slice(1);
  761. } else {
  762. href = href.slice(1, -1);
  763. }
  764. }
  765. return outputLink(cap, {
  766. href: href ? href.replace(this.rules.inline._escapes, '$1') : href,
  767. title: title ? title.replace(this.rules.inline._escapes, '$1') : title
  768. }, cap[0]);
  769. }
  770. };
  771. _proto.reflink = function reflink(src, links) {
  772. var cap;
  773. if ((cap = this.rules.inline.reflink.exec(src)) || (cap = this.rules.inline.nolink.exec(src))) {
  774. var link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
  775. link = links[link.toLowerCase()];
  776. if (!link || !link.href) {
  777. var text = cap[0].charAt(0);
  778. return {
  779. type: 'text',
  780. raw: text,
  781. text: text
  782. };
  783. }
  784. return outputLink(cap, link, cap[0]);
  785. }
  786. };
  787. _proto.emStrong = function emStrong(src, maskedSrc, prevChar) {
  788. if (prevChar === void 0) {
  789. prevChar = '';
  790. }
  791. var match = this.rules.inline.emStrong.lDelim.exec(src);
  792. if (!match) return;
  793. if (match[3] && prevChar.match(/(?:[0-9A-Za-z\xAA\xB2\xB3\xB5\xB9\xBA\xBC-\xBE\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u0660-\u0669\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07C0-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08C7\u0904-\u0939\u093D\u0950\u0958-\u0961\u0966-\u096F\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09E6-\u09F1\u09F4-\u09F9\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A66-\u0A6F\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AE6-\u0AEF\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B66-\u0B6F\u0B71-\u0B77\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0BE6-\u0BF2\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C66-\u0C6F\u0C78-\u0C7E\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CE6-\u0CEF\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D58-\u0D61\u0D66-\u0D78\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DE6-\u0DEF\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F20-\u0F33\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F-\u1049\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u1090-\u1099\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1369-\u137C\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u17E0-\u17E9\u17F0-\u17F9\u1810-\u1819\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A16\u1A20-\u1A54\u1A80-\u1A89\u1A90-\u1A99\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B50-\u1B59\u1B83-\u1BA0\u1BAE-\u1BE5\u1C00-\u1C23\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2070\u2071\u2074-\u2079\u207F-\u2089\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2150-\u2189\u2460-\u249B\u24EA-\u24FF\u2776-\u2793\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2CFD\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u3192-\u3195\u31A0-\u31BF\u31F0-\u31FF\u3220-\u3229\u3248-\u324F\u3251-\u325F\u3280-\u3289\u32B1-\u32BF\u3400-\u4DBF\u4E00-\u9FFC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7BF\uA7C2-\uA7CA\uA7F5-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA830-\uA835\uA840-\uA873\uA882-\uA8B3\uA8D0-\uA8D9\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA900-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF-\uA9D9\uA9E0-\uA9E4\uA9E6-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA50-\uAA59\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD07-\uDD33\uDD40-\uDD78\uDD8A\uDD8B\uDE80-\uDE9C\uDEA0-\uDED0\uDEE1-\uDEFB\uDF00-\uDF23\uDF2D-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC58-\uDC76\uDC79-\uDC9E\uDCA7-\uDCAF\uDCE0-\uDCF2\uDCF4\uDCF5\uDCFB-\uDD1B\uDD20-\uDD39\uDD80-\uDDB7\uDDBC-\uDDCF\uDDD2-\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE40-\uDE48\uDE60-\uDE7E\uDE80-\uDE9F\uDEC0-\uDEC7\uDEC9-\uDEE4\uDEEB-\uDEEF\uDF00-\uDF35\uDF40-\uDF55\uDF58-\uDF72\uDF78-\uDF91\uDFA9-\uDFAF]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDCFA-\uDD23\uDD30-\uDD39\uDE60-\uDE7E\uDE80-\uDEA9\uDEB0\uDEB1\uDF00-\uDF27\uDF30-\uDF45\uDF51-\uDF54\uDFB0-\uDFCB\uDFE0-\uDFF6]|\uD804[\uDC03-\uDC37\uDC52-\uDC6F\uDC83-\uDCAF\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD03-\uDD26\uDD36-\uDD3F\uDD44\uDD47\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDD0-\uDDDA\uDDDC\uDDE1-\uDDF4\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDEF0-\uDEF9\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC50-\uDC59\uDC5F-\uDC61\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE50-\uDE59\uDE80-\uDEAA\uDEB8\uDEC0-\uDEC9\uDF00-\uDF1A\uDF30-\uDF3B]|\uD806[\uDC00-\uDC2B\uDCA0-\uDCF2\uDCFF-\uDD06\uDD09\uDD0C-\uDD13\uDD15\uDD16\uDD18-\uDD2F\uDD3F\uDD41\uDD50-\uDD59\uDDA0-\uDDA7\uDDAA-\uDDD0\uDDE1\uDDE3\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE89\uDE9D\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC50-\uDC6C\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46\uDD50-\uDD59\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD89\uDD98\uDDA0-\uDDA9\uDEE0-\uDEF2\uDFB0\uDFC0-\uDFD4]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD822\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF50-\uDF59\uDF5B-\uDF61\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDE40-\uDE96\uDF00-\uDF4A\uDF50\uDF93-\uDF9F\uDFE0\uDFE1\uDFE3]|\uD821[\uDC00-\uDFF7]|\uD823[\uDC00-\uDCD5\uDD00-\uDD08]|\uD82C[\uDC00-\uDD1E\uDD50-\uDD52\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD834[\uDEE0-\uDEF3\uDF60-\uDF78]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD838[\uDD00-\uDD2C\uDD37-\uDD3D\uDD40-\uDD49\uDD4E\uDEC0-\uDEEB\uDEF0-\uDEF9]|\uD83A[\uDC00-\uDCC4\uDCC7-\uDCCF\uDD00-\uDD43\uDD4B\uDD50-\uDD59]|\uD83B[\uDC71-\uDCAB\uDCAD-\uDCAF\uDCB1-\uDCB4\uDD01-\uDD2D\uDD2F-\uDD3D\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD83C[\uDD00-\uDD0C]|\uD83E[\uDFF0-\uDFF9]|\uD869[\uDC00-\uDEDD\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A])/)) return; // _ can't be between two alphanumerics. \p{L}\p{N} includes non-english alphabet/numbers as well
  794. var nextChar = match[1] || match[2] || '';
  795. if (!nextChar || nextChar && (prevChar === '' || this.rules.inline.punctuation.exec(prevChar))) {
  796. var lLength = match[0].length - 1;
  797. var rDelim,
  798. rLength,
  799. delimTotal = lLength,
  800. midDelimTotal = 0;
  801. var endReg = match[0][0] === '*' ? this.rules.inline.emStrong.rDelimAst : this.rules.inline.emStrong.rDelimUnd;
  802. endReg.lastIndex = 0;
  803. maskedSrc = maskedSrc.slice(-1 * src.length + lLength); // Bump maskedSrc to same section of string as src (move to lexer?)
  804. while ((match = endReg.exec(maskedSrc)) != null) {
  805. rDelim = match[1] || match[2] || match[3] || match[4] || match[5] || match[6];
  806. if (!rDelim) continue; // matched the first alternative in rules.js (skip the * in __abc*abc__)
  807. rLength = rDelim.length;
  808. if (match[3] || match[4]) {
  809. // found another Left Delim
  810. delimTotal += rLength;
  811. continue;
  812. } else if (match[5] || match[6]) {
  813. // either Left or Right Delim
  814. if (lLength % 3 && !((lLength + rLength) % 3)) {
  815. midDelimTotal += rLength;
  816. continue; // CommonMark Emphasis Rules 9-10
  817. }
  818. }
  819. delimTotal -= rLength;
  820. if (delimTotal > 0) continue; // Haven't found enough closing delimiters
  821. // If this is the last rDelimiter, remove extra characters. *a*** -> *a*
  822. if (delimTotal + midDelimTotal - rLength <= 0 && !maskedSrc.slice(endReg.lastIndex).match(endReg)) {
  823. rLength = Math.min(rLength, rLength + delimTotal + midDelimTotal);
  824. }
  825. if (Math.min(lLength, rLength) % 2) {
  826. return {
  827. type: 'em',
  828. raw: src.slice(0, lLength + match.index + rLength + 1),
  829. text: src.slice(1, lLength + match.index + rLength)
  830. };
  831. }
  832. if (Math.min(lLength, rLength) % 2 === 0) {
  833. return {
  834. type: 'strong',
  835. raw: src.slice(0, lLength + match.index + rLength + 1),
  836. text: src.slice(2, lLength + match.index + rLength - 1)
  837. };
  838. }
  839. }
  840. }
  841. };
  842. _proto.codespan = function codespan(src) {
  843. var cap = this.rules.inline.code.exec(src);
  844. if (cap) {
  845. var text = cap[2].replace(/\n/g, ' ');
  846. var hasNonSpaceChars = /[^ ]/.test(text);
  847. var hasSpaceCharsOnBothEnds = /^ /.test(text) && / $/.test(text);
  848. if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {
  849. text = text.substring(1, text.length - 1);
  850. }
  851. text = _escape(text, true);
  852. return {
  853. type: 'codespan',
  854. raw: cap[0],
  855. text: text
  856. };
  857. }
  858. };
  859. _proto.br = function br(src) {
  860. var cap = this.rules.inline.br.exec(src);
  861. if (cap) {
  862. return {
  863. type: 'br',
  864. raw: cap[0]
  865. };
  866. }
  867. };
  868. _proto.del = function del(src) {
  869. var cap = this.rules.inline.del.exec(src);
  870. if (cap) {
  871. return {
  872. type: 'del',
  873. raw: cap[0],
  874. text: cap[2]
  875. };
  876. }
  877. };
  878. _proto.autolink = function autolink(src, mangle) {
  879. var cap = this.rules.inline.autolink.exec(src);
  880. if (cap) {
  881. var text, href;
  882. if (cap[2] === '@') {
  883. text = _escape(this.options.mangle ? mangle(cap[1]) : cap[1]);
  884. href = 'mailto:' + text;
  885. } else {
  886. text = _escape(cap[1]);
  887. href = text;
  888. }
  889. return {
  890. type: 'link',
  891. raw: cap[0],
  892. text: text,
  893. href: href,
  894. tokens: [{
  895. type: 'text',
  896. raw: text,
  897. text: text
  898. }]
  899. };
  900. }
  901. };
  902. _proto.url = function url(src, mangle) {
  903. var cap;
  904. if (cap = this.rules.inline.url.exec(src)) {
  905. var text, href;
  906. if (cap[2] === '@') {
  907. text = _escape(this.options.mangle ? mangle(cap[0]) : cap[0]);
  908. href = 'mailto:' + text;
  909. } else {
  910. // do extended autolink path validation
  911. var prevCapZero;
  912. do {
  913. prevCapZero = cap[0];
  914. cap[0] = this.rules.inline._backpedal.exec(cap[0])[0];
  915. } while (prevCapZero !== cap[0]);
  916. text = _escape(cap[0]);
  917. if (cap[1] === 'www.') {
  918. href = 'http://' + text;
  919. } else {
  920. href = text;
  921. }
  922. }
  923. return {
  924. type: 'link',
  925. raw: cap[0],
  926. text: text,
  927. href: href,
  928. tokens: [{
  929. type: 'text',
  930. raw: text,
  931. text: text
  932. }]
  933. };
  934. }
  935. };
  936. _proto.inlineText = function inlineText(src, inRawBlock, smartypants) {
  937. var cap = this.rules.inline.text.exec(src);
  938. if (cap) {
  939. var text;
  940. if (inRawBlock) {
  941. text = this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : _escape(cap[0]) : cap[0];
  942. } else {
  943. text = _escape(this.options.smartypants ? smartypants(cap[0]) : cap[0]);
  944. }
  945. return {
  946. type: 'text',
  947. raw: cap[0],
  948. text: text
  949. };
  950. }
  951. };
  952. return Tokenizer;
  953. }();
  954. var noopTest$1 = helpers.noopTest,
  955. edit$1 = helpers.edit,
  956. merge$1 = helpers.merge;
  957. /**
  958. * Block-Level Grammar
  959. */
  960. var block = {
  961. newline: /^(?: *(?:\n|$))+/,
  962. code: /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,
  963. fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,
  964. hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
  965. heading: /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,
  966. blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
  967. list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?! {0,3}bull )\n*|\s*$)/,
  968. html: '^ {0,3}(?:' // optional indentation
  969. + '<(script|pre|style)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
  970. + '|comment[^\\n]*(\\n+|$)' // (2)
  971. + '|<\\?[\\s\\S]*?(?:\\?>\\n*|$)' // (3)
  972. + '|<![A-Z][\\s\\S]*?(?:>\\n*|$)' // (4)
  973. + '|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)' // (5)
  974. + '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:\\n{2,}|$)' // (6)
  975. + '|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag
  976. + '|</(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag
  977. + ')',
  978. def: /^ {0,3}\[(label)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,
  979. nptable: noopTest$1,
  980. table: noopTest$1,
  981. lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,
  982. // regex template, placeholders will be replaced according to different paragraph
  983. // interruption rules of commonmark and the original markdown spec:
  984. _paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html| +\n)[^\n]+)*)/,
  985. text: /^[^\n]+/
  986. };
  987. block._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/;
  988. block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/;
  989. block.def = edit$1(block.def).replace('label', block._label).replace('title', block._title).getRegex();
  990. block.bullet = /(?:[*+-]|\d{1,9}[.)])/;
  991. block.item = /^( *)(bull) ?[^\n]*(?:\n(?! *bull ?)[^\n]*)*/;
  992. block.item = edit$1(block.item, 'gm').replace(/bull/g, block.bullet).getRegex();
  993. block.listItemStart = edit$1(/^( *)(bull) */).replace('bull', block.bullet).getRegex();
  994. 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();
  995. 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';
  996. block._comment = /<!--(?!-?>)[\s\S]*?(?:-->|$)/;
  997. 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();
  998. 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
  999. .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
  1000. .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)').replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
  1001. .getRegex();
  1002. block.blockquote = edit$1(block.blockquote).replace('paragraph', block.paragraph).getRegex();
  1003. /**
  1004. * Normal Block Grammar
  1005. */
  1006. block.normal = merge$1({}, block);
  1007. /**
  1008. * GFM Block Grammar
  1009. */
  1010. block.gfm = merge$1({}, block.normal, {
  1011. nptable: '^ *([^|\\n ].*\\|.*)\\n' // Header
  1012. + ' {0,3}([-:]+ *\\|[-| :]*)' // Align
  1013. + '(?:\\n((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)',
  1014. // Cells
  1015. table: '^ *\\|(.+)\\n' // Header
  1016. + ' {0,3}\\|?( *[-:]+[-| :]*)' // Align
  1017. + '(?:\\n *((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells
  1018. });
  1019. 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
  1020. .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)').replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
  1021. .getRegex();
  1022. 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
  1023. .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)').replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
  1024. .getRegex();
  1025. /**
  1026. * Pedantic grammar (original John Gruber's loose markdown specification)
  1027. */
  1028. block.pedantic = merge$1({}, block.normal, {
  1029. html: edit$1('^ *(?:comment *(?:\\n|\\s*$)' + '|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)' // closed tag
  1030. + '|<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(),
  1031. def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
  1032. heading: /^(#{1,6})(.*)(?:\n+|$)/,
  1033. fences: noopTest$1,
  1034. // fences not supported
  1035. 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()
  1036. });
  1037. /**
  1038. * Inline-Level Grammar
  1039. */
  1040. var inline = {
  1041. escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,
  1042. autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
  1043. url: noopTest$1,
  1044. tag: '^comment' + '|^</[a-zA-Z][\\w:-]*\\s*>' // self-closing tag
  1045. + '|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>' // open tag
  1046. + '|^<\\?[\\s\\S]*?\\?>' // processing instruction, e.g. <?php ?>
  1047. + '|^<![a-zA-Z]+\\s[\\s\\S]*?>' // declaration, e.g. <!DOCTYPE html>
  1048. + '|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>',
  1049. // CDATA section
  1050. link: /^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,
  1051. reflink: /^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,
  1052. nolink: /^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,
  1053. reflinkSearch: 'reflink|nolink(?!\\()',
  1054. emStrong: {
  1055. lDelim: /^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,
  1056. // (1) and (2) can only be a Right Delimiter. (3) and (4) can only be Left. (5) and (6) can be either Left or Right.
  1057. // () Skip other delimiter (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a
  1058. rDelimAst: /\_\_[^_]*?\*[^_]*?\_\_|[punct_](\*+)(?=[\s]|$)|[^punct*_\s](\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|[^punct*_\s](\*+)(?=[^punct*_\s])/,
  1059. rDelimUnd: /\*\*[^*]*?\_[^*]*?\*\*|[punct*](\_+)(?=[\s]|$)|[^punct*_\s](\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/ // ^- Not allowed for _
  1060. },
  1061. code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
  1062. br: /^( {2,}|\\)\n(?!\s*$)/,
  1063. del: noopTest$1,
  1064. text: /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,
  1065. punctuation: /^([\spunctuation])/
  1066. }; // list of punctuation marks from CommonMark spec
  1067. // without * and _ to handle the different emphasis markers * and _
  1068. inline._punctuation = '!"#$%&\'()+\\-.,/:;<=>?@\\[\\]`^{|}~';
  1069. inline.punctuation = edit$1(inline.punctuation).replace(/punctuation/g, inline._punctuation).getRegex(); // sequences em should skip over [title](link), `code`, <html>
  1070. inline.blockSkip = /\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g;
  1071. inline.escapedEmSt = /\\\*|\\_/g;
  1072. inline._comment = edit$1(block._comment).replace('(?:-->|$)', '-->').getRegex();
  1073. inline.emStrong.lDelim = edit$1(inline.emStrong.lDelim).replace(/punct/g, inline._punctuation).getRegex();
  1074. inline.emStrong.rDelimAst = edit$1(inline.emStrong.rDelimAst, 'g').replace(/punct/g, inline._punctuation).getRegex();
  1075. inline.emStrong.rDelimUnd = edit$1(inline.emStrong.rDelimUnd, 'g').replace(/punct/g, inline._punctuation).getRegex();
  1076. inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g;
  1077. inline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
  1078. 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])?)+(?![-_])/;
  1079. inline.autolink = edit$1(inline.autolink).replace('scheme', inline._scheme).replace('email', inline._email).getRegex();
  1080. inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/;
  1081. inline.tag = edit$1(inline.tag).replace('comment', inline._comment).replace('attribute', inline._attribute).getRegex();
  1082. inline._label = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
  1083. inline._href = /<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/;
  1084. inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/;
  1085. inline.link = edit$1(inline.link).replace('label', inline._label).replace('href', inline._href).replace('title', inline._title).getRegex();
  1086. inline.reflink = edit$1(inline.reflink).replace('label', inline._label).getRegex();
  1087. inline.reflinkSearch = edit$1(inline.reflinkSearch, 'g').replace('reflink', inline.reflink).replace('nolink', inline.nolink).getRegex();
  1088. /**
  1089. * Normal Inline Grammar
  1090. */
  1091. inline.normal = merge$1({}, inline);
  1092. /**
  1093. * Pedantic Inline Grammar
  1094. */
  1095. inline.pedantic = merge$1({}, inline.normal, {
  1096. strong: {
  1097. start: /^__|\*\*/,
  1098. middle: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
  1099. endAst: /\*\*(?!\*)/g,
  1100. endUnd: /__(?!_)/g
  1101. },
  1102. em: {
  1103. start: /^_|\*/,
  1104. middle: /^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,
  1105. endAst: /\*(?!\*)/g,
  1106. endUnd: /_(?!_)/g
  1107. },
  1108. link: edit$1(/^!?\[(label)\]\((.*?)\)/).replace('label', inline._label).getRegex(),
  1109. reflink: edit$1(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace('label', inline._label).getRegex()
  1110. });
  1111. /**
  1112. * GFM Inline Grammar
  1113. */
  1114. inline.gfm = merge$1({}, inline.normal, {
  1115. escape: edit$1(inline.escape).replace('])', '~|])').getRegex(),
  1116. _extended_email: /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,
  1117. url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
  1118. _backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,
  1119. del: /^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,
  1120. text: /^([`~]+|[^`~])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))/
  1121. });
  1122. inline.gfm.url = edit$1(inline.gfm.url, 'i').replace('email', inline.gfm._extended_email).getRegex();
  1123. /**
  1124. * GFM + Line Breaks Inline Grammar
  1125. */
  1126. inline.breaks = merge$1({}, inline.gfm, {
  1127. br: edit$1(inline.br).replace('{2,}', '*').getRegex(),
  1128. text: edit$1(inline.gfm.text).replace('\\b_', '\\b_| {2,}\\n').replace(/\{2,\}/g, '*').getRegex()
  1129. });
  1130. var rules = {
  1131. block: block,
  1132. inline: inline
  1133. };
  1134. var defaults$2 = defaults.defaults;
  1135. var block$1 = rules.block,
  1136. inline$1 = rules.inline;
  1137. var repeatString$1 = helpers.repeatString;
  1138. /**
  1139. * smartypants text replacement
  1140. */
  1141. function smartypants(text) {
  1142. return text // em-dashes
  1143. .replace(/---/g, "\u2014") // en-dashes
  1144. .replace(/--/g, "\u2013") // opening singles
  1145. .replace(/(^|[-\u2014/(\[{"\s])'/g, "$1\u2018") // closing singles & apostrophes
  1146. .replace(/'/g, "\u2019") // opening doubles
  1147. .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, "$1\u201C") // closing doubles
  1148. .replace(/"/g, "\u201D") // ellipses
  1149. .replace(/\.{3}/g, "\u2026");
  1150. }
  1151. /**
  1152. * mangle email addresses
  1153. */
  1154. function mangle(text) {
  1155. var out = '',
  1156. i,
  1157. ch;
  1158. var l = text.length;
  1159. for (i = 0; i < l; i++) {
  1160. ch = text.charCodeAt(i);
  1161. if (Math.random() > 0.5) {
  1162. ch = 'x' + ch.toString(16);
  1163. }
  1164. out += '&#' + ch + ';';
  1165. }
  1166. return out;
  1167. }
  1168. /**
  1169. * Block Lexer
  1170. */
  1171. var Lexer_1 = /*#__PURE__*/function () {
  1172. function Lexer(options) {
  1173. this.tokens = [];
  1174. this.tokens.links = Object.create(null);
  1175. this.options = options || defaults$2;
  1176. this.options.tokenizer = this.options.tokenizer || new Tokenizer_1();
  1177. this.tokenizer = this.options.tokenizer;
  1178. this.tokenizer.options = this.options;
  1179. var rules = {
  1180. block: block$1.normal,
  1181. inline: inline$1.normal
  1182. };
  1183. if (this.options.pedantic) {
  1184. rules.block = block$1.pedantic;
  1185. rules.inline = inline$1.pedantic;
  1186. } else if (this.options.gfm) {
  1187. rules.block = block$1.gfm;
  1188. if (this.options.breaks) {
  1189. rules.inline = inline$1.breaks;
  1190. } else {
  1191. rules.inline = inline$1.gfm;
  1192. }
  1193. }
  1194. this.tokenizer.rules = rules;
  1195. }
  1196. /**
  1197. * Expose Rules
  1198. */
  1199. /**
  1200. * Static Lex Method
  1201. */
  1202. Lexer.lex = function lex(src, options) {
  1203. var lexer = new Lexer(options);
  1204. return lexer.lex(src);
  1205. }
  1206. /**
  1207. * Static Lex Inline Method
  1208. */
  1209. ;
  1210. Lexer.lexInline = function lexInline(src, options) {
  1211. var lexer = new Lexer(options);
  1212. return lexer.inlineTokens(src);
  1213. }
  1214. /**
  1215. * Preprocessing
  1216. */
  1217. ;
  1218. var _proto = Lexer.prototype;
  1219. _proto.lex = function lex(src) {
  1220. src = src.replace(/\r\n|\r/g, '\n').replace(/\t/g, ' ');
  1221. this.blockTokens(src, this.tokens, true);
  1222. this.inline(this.tokens);
  1223. return this.tokens;
  1224. }
  1225. /**
  1226. * Lexing
  1227. */
  1228. ;
  1229. _proto.blockTokens = function blockTokens(src, tokens, top) {
  1230. if (tokens === void 0) {
  1231. tokens = [];
  1232. }
  1233. if (top === void 0) {
  1234. top = true;
  1235. }
  1236. if (this.options.pedantic) {
  1237. src = src.replace(/^ +$/gm, '');
  1238. }
  1239. var token, i, l, lastToken;
  1240. while (src) {
  1241. // newline
  1242. if (token = this.tokenizer.space(src)) {
  1243. src = src.substring(token.raw.length);
  1244. if (token.type) {
  1245. tokens.push(token);
  1246. }
  1247. continue;
  1248. } // code
  1249. if (token = this.tokenizer.code(src)) {
  1250. src = src.substring(token.raw.length);
  1251. lastToken = tokens[tokens.length - 1]; // An indented code block cannot interrupt a paragraph.
  1252. if (lastToken && lastToken.type === 'paragraph') {
  1253. lastToken.raw += '\n' + token.raw;
  1254. lastToken.text += '\n' + token.text;
  1255. } else {
  1256. tokens.push(token);
  1257. }
  1258. continue;
  1259. } // fences
  1260. if (token = this.tokenizer.fences(src)) {
  1261. src = src.substring(token.raw.length);
  1262. tokens.push(token);
  1263. continue;
  1264. } // heading
  1265. if (token = this.tokenizer.heading(src)) {
  1266. src = src.substring(token.raw.length);
  1267. tokens.push(token);
  1268. continue;
  1269. } // table no leading pipe (gfm)
  1270. if (token = this.tokenizer.nptable(src)) {
  1271. src = src.substring(token.raw.length);
  1272. tokens.push(token);
  1273. continue;
  1274. } // hr
  1275. if (token = this.tokenizer.hr(src)) {
  1276. src = src.substring(token.raw.length);
  1277. tokens.push(token);
  1278. continue;
  1279. } // blockquote
  1280. if (token = this.tokenizer.blockquote(src)) {
  1281. src = src.substring(token.raw.length);
  1282. token.tokens = this.blockTokens(token.text, [], top);
  1283. tokens.push(token);
  1284. continue;
  1285. } // list
  1286. if (token = this.tokenizer.list(src)) {
  1287. src = src.substring(token.raw.length);
  1288. l = token.items.length;
  1289. for (i = 0; i < l; i++) {
  1290. token.items[i].tokens = this.blockTokens(token.items[i].text, [], false);
  1291. }
  1292. tokens.push(token);
  1293. continue;
  1294. } // html
  1295. if (token = this.tokenizer.html(src)) {
  1296. src = src.substring(token.raw.length);
  1297. tokens.push(token);
  1298. continue;
  1299. } // def
  1300. if (top && (token = this.tokenizer.def(src))) {
  1301. src = src.substring(token.raw.length);
  1302. if (!this.tokens.links[token.tag]) {
  1303. this.tokens.links[token.tag] = {
  1304. href: token.href,
  1305. title: token.title
  1306. };
  1307. }
  1308. continue;
  1309. } // table (gfm)
  1310. if (token = this.tokenizer.table(src)) {
  1311. src = src.substring(token.raw.length);
  1312. tokens.push(token);
  1313. continue;
  1314. } // lheading
  1315. if (token = this.tokenizer.lheading(src)) {
  1316. src = src.substring(token.raw.length);
  1317. tokens.push(token);
  1318. continue;
  1319. } // top-level paragraph
  1320. if (top && (token = this.tokenizer.paragraph(src))) {
  1321. src = src.substring(token.raw.length);
  1322. tokens.push(token);
  1323. continue;
  1324. } // text
  1325. if (token = this.tokenizer.text(src)) {
  1326. src = src.substring(token.raw.length);
  1327. lastToken = tokens[tokens.length - 1];
  1328. if (lastToken && lastToken.type === 'text') {
  1329. lastToken.raw += '\n' + token.raw;
  1330. lastToken.text += '\n' + token.text;
  1331. } else {
  1332. tokens.push(token);
  1333. }
  1334. continue;
  1335. }
  1336. if (src) {
  1337. var errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
  1338. if (this.options.silent) {
  1339. console.error(errMsg);
  1340. break;
  1341. } else {
  1342. throw new Error(errMsg);
  1343. }
  1344. }
  1345. }
  1346. return tokens;
  1347. };
  1348. _proto.inline = function inline(tokens) {
  1349. var i, j, k, l2, row, token;
  1350. var l = tokens.length;
  1351. for (i = 0; i < l; i++) {
  1352. token = tokens[i];
  1353. switch (token.type) {
  1354. case 'paragraph':
  1355. case 'text':
  1356. case 'heading':
  1357. {
  1358. token.tokens = [];
  1359. this.inlineTokens(token.text, token.tokens);
  1360. break;
  1361. }
  1362. case 'table':
  1363. {
  1364. token.tokens = {
  1365. header: [],
  1366. cells: []
  1367. }; // header
  1368. l2 = token.header.length;
  1369. for (j = 0; j < l2; j++) {
  1370. token.tokens.header[j] = [];
  1371. this.inlineTokens(token.header[j], token.tokens.header[j]);
  1372. } // cells
  1373. l2 = token.cells.length;
  1374. for (j = 0; j < l2; j++) {
  1375. row = token.cells[j];
  1376. token.tokens.cells[j] = [];
  1377. for (k = 0; k < row.length; k++) {
  1378. token.tokens.cells[j][k] = [];
  1379. this.inlineTokens(row[k], token.tokens.cells[j][k]);
  1380. }
  1381. }
  1382. break;
  1383. }
  1384. case 'blockquote':
  1385. {
  1386. this.inline(token.tokens);
  1387. break;
  1388. }
  1389. case 'list':
  1390. {
  1391. l2 = token.items.length;
  1392. for (j = 0; j < l2; j++) {
  1393. this.inline(token.items[j].tokens);
  1394. }
  1395. break;
  1396. }
  1397. }
  1398. }
  1399. return tokens;
  1400. }
  1401. /**
  1402. * Lexing/Compiling
  1403. */
  1404. ;
  1405. _proto.inlineTokens = function inlineTokens(src, tokens, inLink, inRawBlock) {
  1406. if (tokens === void 0) {
  1407. tokens = [];
  1408. }
  1409. if (inLink === void 0) {
  1410. inLink = false;
  1411. }
  1412. if (inRawBlock === void 0) {
  1413. inRawBlock = false;
  1414. }
  1415. var token, lastToken; // String with links masked to avoid interference with em and strong
  1416. var maskedSrc = src;
  1417. var match;
  1418. var keepPrevChar, prevChar; // Mask out reflinks
  1419. if (this.tokens.links) {
  1420. var links = Object.keys(this.tokens.links);
  1421. if (links.length > 0) {
  1422. while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
  1423. if (links.includes(match[0].slice(match[0].lastIndexOf('[') + 1, -1))) {
  1424. maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString$1('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
  1425. }
  1426. }
  1427. }
  1428. } // Mask out other blocks
  1429. while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
  1430. maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString$1('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
  1431. } // Mask out escaped em & strong delimiters
  1432. while ((match = this.tokenizer.rules.inline.escapedEmSt.exec(maskedSrc)) != null) {
  1433. maskedSrc = maskedSrc.slice(0, match.index) + '++' + maskedSrc.slice(this.tokenizer.rules.inline.escapedEmSt.lastIndex);
  1434. }
  1435. while (src) {
  1436. if (!keepPrevChar) {
  1437. prevChar = '';
  1438. }
  1439. keepPrevChar = false; // escape
  1440. if (token = this.tokenizer.escape(src)) {
  1441. src = src.substring(token.raw.length);
  1442. tokens.push(token);
  1443. continue;
  1444. } // tag
  1445. if (token = this.tokenizer.tag(src, inLink, inRawBlock)) {
  1446. src = src.substring(token.raw.length);
  1447. inLink = token.inLink;
  1448. inRawBlock = token.inRawBlock;
  1449. var _lastToken = tokens[tokens.length - 1];
  1450. if (_lastToken && token.type === 'text' && _lastToken.type === 'text') {
  1451. _lastToken.raw += token.raw;
  1452. _lastToken.text += token.text;
  1453. } else {
  1454. tokens.push(token);
  1455. }
  1456. continue;
  1457. } // link
  1458. if (token = this.tokenizer.link(src)) {
  1459. src = src.substring(token.raw.length);
  1460. if (token.type === 'link') {
  1461. token.tokens = this.inlineTokens(token.text, [], true, inRawBlock);
  1462. }
  1463. tokens.push(token);
  1464. continue;
  1465. } // reflink, nolink
  1466. if (token = this.tokenizer.reflink(src, this.tokens.links)) {
  1467. src = src.substring(token.raw.length);
  1468. var _lastToken2 = tokens[tokens.length - 1];
  1469. if (token.type === 'link') {
  1470. token.tokens = this.inlineTokens(token.text, [], true, inRawBlock);
  1471. tokens.push(token);
  1472. } else if (_lastToken2 && token.type === 'text' && _lastToken2.type === 'text') {
  1473. _lastToken2.raw += token.raw;
  1474. _lastToken2.text += token.text;
  1475. } else {
  1476. tokens.push(token);
  1477. }
  1478. continue;
  1479. } // em & strong
  1480. if (token = this.tokenizer.emStrong(src, maskedSrc, prevChar)) {
  1481. src = src.substring(token.raw.length);
  1482. token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
  1483. tokens.push(token);
  1484. continue;
  1485. } // code
  1486. if (token = this.tokenizer.codespan(src)) {
  1487. src = src.substring(token.raw.length);
  1488. tokens.push(token);
  1489. continue;
  1490. } // br
  1491. if (token = this.tokenizer.br(src)) {
  1492. src = src.substring(token.raw.length);
  1493. tokens.push(token);
  1494. continue;
  1495. } // del (gfm)
  1496. if (token = this.tokenizer.del(src)) {
  1497. src = src.substring(token.raw.length);
  1498. token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
  1499. tokens.push(token);
  1500. continue;
  1501. } // autolink
  1502. if (token = this.tokenizer.autolink(src, mangle)) {
  1503. src = src.substring(token.raw.length);
  1504. tokens.push(token);
  1505. continue;
  1506. } // url (gfm)
  1507. if (!inLink && (token = this.tokenizer.url(src, mangle))) {
  1508. src = src.substring(token.raw.length);
  1509. tokens.push(token);
  1510. continue;
  1511. } // text
  1512. if (token = this.tokenizer.inlineText(src, inRawBlock, smartypants)) {
  1513. src = src.substring(token.raw.length);
  1514. if (token.raw.slice(-1) !== '_') {
  1515. // Track prevChar before string of ____ started
  1516. prevChar = token.raw.slice(-1);
  1517. }
  1518. keepPrevChar = true;
  1519. lastToken = tokens[tokens.length - 1];
  1520. if (lastToken && lastToken.type === 'text') {
  1521. lastToken.raw += token.raw;
  1522. lastToken.text += token.text;
  1523. } else {
  1524. tokens.push(token);
  1525. }
  1526. continue;
  1527. }
  1528. if (src) {
  1529. var errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
  1530. if (this.options.silent) {
  1531. console.error(errMsg);
  1532. break;
  1533. } else {
  1534. throw new Error(errMsg);
  1535. }
  1536. }
  1537. }
  1538. return tokens;
  1539. };
  1540. _createClass(Lexer, null, [{
  1541. key: "rules",
  1542. get: function get() {
  1543. return {
  1544. block: block$1,
  1545. inline: inline$1
  1546. };
  1547. }
  1548. }]);
  1549. return Lexer;
  1550. }();
  1551. var defaults$3 = defaults.defaults;
  1552. var cleanUrl$1 = helpers.cleanUrl,
  1553. escape$1 = helpers.escape;
  1554. /**
  1555. * Renderer
  1556. */
  1557. var Renderer_1 = /*#__PURE__*/function () {
  1558. function Renderer(options) {
  1559. this.options = options || defaults$3;
  1560. }
  1561. var _proto = Renderer.prototype;
  1562. _proto.code = function code(_code, infostring, escaped) {
  1563. var lang = (infostring || '').match(/\S*/)[0];
  1564. if (this.options.highlight) {
  1565. var out = this.options.highlight(_code, lang);
  1566. if (out != null && out !== _code) {
  1567. escaped = true;
  1568. _code = out;
  1569. }
  1570. }
  1571. _code = _code.replace(/\n$/, '') + '\n';
  1572. if (!lang) {
  1573. return '<pre><code>' + (escaped ? _code : escape$1(_code, true)) + '</code></pre>\n';
  1574. }
  1575. return '<pre><code class="' + this.options.langPrefix + escape$1(lang, true) + '">' + (escaped ? _code : escape$1(_code, true)) + '</code></pre>\n';
  1576. };
  1577. _proto.blockquote = function blockquote(quote) {
  1578. return '<blockquote>\n' + quote + '</blockquote>\n';
  1579. };
  1580. _proto.html = function html(_html) {
  1581. return _html;
  1582. };
  1583. _proto.heading = function heading(text, level, raw, slugger) {
  1584. if (this.options.headerIds) {
  1585. return '<h' + level + ' id="' + this.options.headerPrefix + slugger.slug(raw) + '">' + text + '</h' + level + '>\n';
  1586. } // ignore IDs
  1587. return '<h' + level + '>' + text + '</h' + level + '>\n';
  1588. };
  1589. _proto.hr = function hr() {
  1590. return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
  1591. };
  1592. _proto.list = function list(body, ordered, start) {
  1593. var type = ordered ? 'ol' : 'ul',
  1594. startatt = ordered && start !== 1 ? ' start="' + start + '"' : '';
  1595. return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
  1596. };
  1597. _proto.listitem = function listitem(text) {
  1598. return '<li>' + text + '</li>\n';
  1599. };
  1600. _proto.checkbox = function checkbox(checked) {
  1601. return '<input ' + (checked ? 'checked="" ' : '') + 'disabled="" type="checkbox"' + (this.options.xhtml ? ' /' : '') + '> ';
  1602. };
  1603. _proto.paragraph = function paragraph(text) {
  1604. return '<p>' + text + '</p>\n';
  1605. };
  1606. _proto.table = function table(header, body) {
  1607. if (body) body = '<tbody>' + body + '</tbody>';
  1608. return '<table>\n' + '<thead>\n' + header + '</thead>\n' + body + '</table>\n';
  1609. };
  1610. _proto.tablerow = function tablerow(content) {
  1611. return '<tr>\n' + content + '</tr>\n';
  1612. };
  1613. _proto.tablecell = function tablecell(content, flags) {
  1614. var type = flags.header ? 'th' : 'td';
  1615. var tag = flags.align ? '<' + type + ' align="' + flags.align + '">' : '<' + type + '>';
  1616. return tag + content + '</' + type + '>\n';
  1617. } // span level renderer
  1618. ;
  1619. _proto.strong = function strong(text) {
  1620. return '<strong>' + text + '</strong>';
  1621. };
  1622. _proto.em = function em(text) {
  1623. return '<em>' + text + '</em>';
  1624. };
  1625. _proto.codespan = function codespan(text) {
  1626. return '<code>' + text + '</code>';
  1627. };
  1628. _proto.br = function br() {
  1629. return this.options.xhtml ? '<br/>' : '<br>';
  1630. };
  1631. _proto.del = function del(text) {
  1632. return '<del>' + text + '</del>';
  1633. };
  1634. _proto.link = function link(href, title, text) {
  1635. href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href);
  1636. if (href === null) {
  1637. return text;
  1638. }
  1639. var out = '<a href="' + escape$1(href) + '"';
  1640. if (title) {
  1641. out += ' title="' + title + '"';
  1642. }
  1643. out += '>' + text + '</a>';
  1644. return out;
  1645. };
  1646. _proto.image = function image(href, title, text) {
  1647. href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href);
  1648. if (href === null) {
  1649. return text;
  1650. }
  1651. var out = '<img src="' + href + '" alt="' + text + '"';
  1652. if (title) {
  1653. out += ' title="' + title + '"';
  1654. }
  1655. out += this.options.xhtml ? '/>' : '>';
  1656. return out;
  1657. };
  1658. _proto.text = function text(_text) {
  1659. return _text;
  1660. };
  1661. return Renderer;
  1662. }();
  1663. /**
  1664. * TextRenderer
  1665. * returns only the textual part of the token
  1666. */
  1667. var TextRenderer_1 = /*#__PURE__*/function () {
  1668. function TextRenderer() {}
  1669. var _proto = TextRenderer.prototype;
  1670. // no need for block level renderers
  1671. _proto.strong = function strong(text) {
  1672. return text;
  1673. };
  1674. _proto.em = function em(text) {
  1675. return text;
  1676. };
  1677. _proto.codespan = function codespan(text) {
  1678. return text;
  1679. };
  1680. _proto.del = function del(text) {
  1681. return text;
  1682. };
  1683. _proto.html = function html(text) {
  1684. return text;
  1685. };
  1686. _proto.text = function text(_text) {
  1687. return _text;
  1688. };
  1689. _proto.link = function link(href, title, text) {
  1690. return '' + text;
  1691. };
  1692. _proto.image = function image(href, title, text) {
  1693. return '' + text;
  1694. };
  1695. _proto.br = function br() {
  1696. return '';
  1697. };
  1698. return TextRenderer;
  1699. }();
  1700. /**
  1701. * Slugger generates header id
  1702. */
  1703. var Slugger_1 = /*#__PURE__*/function () {
  1704. function Slugger() {
  1705. this.seen = {};
  1706. }
  1707. var _proto = Slugger.prototype;
  1708. _proto.serialize = function serialize(value) {
  1709. return value.toLowerCase().trim() // remove html tags
  1710. .replace(/<[!\/a-z].*?>/ig, '') // remove unwanted chars
  1711. .replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '').replace(/\s/g, '-');
  1712. }
  1713. /**
  1714. * Finds the next safe (unique) slug to use
  1715. */
  1716. ;
  1717. _proto.getNextSafeSlug = function getNextSafeSlug(originalSlug, isDryRun) {
  1718. var slug = originalSlug;
  1719. var occurenceAccumulator = 0;
  1720. if (this.seen.hasOwnProperty(slug)) {
  1721. occurenceAccumulator = this.seen[originalSlug];
  1722. do {
  1723. occurenceAccumulator++;
  1724. slug = originalSlug + '-' + occurenceAccumulator;
  1725. } while (this.seen.hasOwnProperty(slug));
  1726. }
  1727. if (!isDryRun) {
  1728. this.seen[originalSlug] = occurenceAccumulator;
  1729. this.seen[slug] = 0;
  1730. }
  1731. return slug;
  1732. }
  1733. /**
  1734. * Convert string to unique id
  1735. * @param {object} options
  1736. * @param {boolean} options.dryrun Generates the next unique slug without updating the internal accumulator.
  1737. */
  1738. ;
  1739. _proto.slug = function slug(value, options) {
  1740. if (options === void 0) {
  1741. options = {};
  1742. }
  1743. var slug = this.serialize(value);
  1744. return this.getNextSafeSlug(slug, options.dryrun);
  1745. };
  1746. return Slugger;
  1747. }();
  1748. var defaults$4 = defaults.defaults;
  1749. var unescape$1 = helpers.unescape;
  1750. /**
  1751. * Parsing & Compiling
  1752. */
  1753. var Parser_1 = /*#__PURE__*/function () {
  1754. function Parser(options) {
  1755. this.options = options || defaults$4;
  1756. this.options.renderer = this.options.renderer || new Renderer_1();
  1757. this.renderer = this.options.renderer;
  1758. this.renderer.options = this.options;
  1759. this.textRenderer = new TextRenderer_1();
  1760. this.slugger = new Slugger_1();
  1761. }
  1762. /**
  1763. * Static Parse Method
  1764. */
  1765. Parser.parse = function parse(tokens, options) {
  1766. var parser = new Parser(options);
  1767. return parser.parse(tokens);
  1768. }
  1769. /**
  1770. * Static Parse Inline Method
  1771. */
  1772. ;
  1773. Parser.parseInline = function parseInline(tokens, options) {
  1774. var parser = new Parser(options);
  1775. return parser.parseInline(tokens);
  1776. }
  1777. /**
  1778. * Parse Loop
  1779. */
  1780. ;
  1781. var _proto = Parser.prototype;
  1782. _proto.parse = function parse(tokens, top) {
  1783. if (top === void 0) {
  1784. top = true;
  1785. }
  1786. var out = '',
  1787. i,
  1788. j,
  1789. k,
  1790. l2,
  1791. l3,
  1792. row,
  1793. cell,
  1794. header,
  1795. body,
  1796. token,
  1797. ordered,
  1798. start,
  1799. loose,
  1800. itemBody,
  1801. item,
  1802. checked,
  1803. task,
  1804. checkbox;
  1805. var l = tokens.length;
  1806. for (i = 0; i < l; i++) {
  1807. token = tokens[i];
  1808. switch (token.type) {
  1809. case 'space':
  1810. {
  1811. continue;
  1812. }
  1813. case 'hr':
  1814. {
  1815. out += this.renderer.hr();
  1816. continue;
  1817. }
  1818. case 'heading':
  1819. {
  1820. out += this.renderer.heading(this.parseInline(token.tokens), token.depth, unescape$1(this.parseInline(token.tokens, this.textRenderer)), this.slugger);
  1821. continue;
  1822. }
  1823. case 'code':
  1824. {
  1825. out += this.renderer.code(token.text, token.lang, token.escaped);
  1826. continue;
  1827. }
  1828. case 'table':
  1829. {
  1830. header = ''; // header
  1831. cell = '';
  1832. l2 = token.header.length;
  1833. for (j = 0; j < l2; j++) {
  1834. cell += this.renderer.tablecell(this.parseInline(token.tokens.header[j]), {
  1835. header: true,
  1836. align: token.align[j]
  1837. });
  1838. }
  1839. header += this.renderer.tablerow(cell);
  1840. body = '';
  1841. l2 = token.cells.length;
  1842. for (j = 0; j < l2; j++) {
  1843. row = token.tokens.cells[j];
  1844. cell = '';
  1845. l3 = row.length;
  1846. for (k = 0; k < l3; k++) {
  1847. cell += this.renderer.tablecell(this.parseInline(row[k]), {
  1848. header: false,
  1849. align: token.align[k]
  1850. });
  1851. }
  1852. body += this.renderer.tablerow(cell);
  1853. }
  1854. out += this.renderer.table(header, body);
  1855. continue;
  1856. }
  1857. case 'blockquote':
  1858. {
  1859. body = this.parse(token.tokens);
  1860. out += this.renderer.blockquote(body);
  1861. continue;
  1862. }
  1863. case 'list':
  1864. {
  1865. ordered = token.ordered;
  1866. start = token.start;
  1867. loose = token.loose;
  1868. l2 = token.items.length;
  1869. body = '';
  1870. for (j = 0; j < l2; j++) {
  1871. item = token.items[j];
  1872. checked = item.checked;
  1873. task = item.task;
  1874. itemBody = '';
  1875. if (item.task) {
  1876. checkbox = this.renderer.checkbox(checked);
  1877. if (loose) {
  1878. if (item.tokens.length > 0 && item.tokens[0].type === 'text') {
  1879. item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
  1880. if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {
  1881. item.tokens[0].tokens[0].text = checkbox + ' ' + item.tokens[0].tokens[0].text;
  1882. }
  1883. } else {
  1884. item.tokens.unshift({
  1885. type: 'text',
  1886. text: checkbox
  1887. });
  1888. }
  1889. } else {
  1890. itemBody += checkbox;
  1891. }
  1892. }
  1893. itemBody += this.parse(item.tokens, loose);
  1894. body += this.renderer.listitem(itemBody, task, checked);
  1895. }
  1896. out += this.renderer.list(body, ordered, start);
  1897. continue;
  1898. }
  1899. case 'html':
  1900. {
  1901. // TODO parse inline content if parameter markdown=1
  1902. out += this.renderer.html(token.text);
  1903. continue;
  1904. }
  1905. case 'paragraph':
  1906. {
  1907. out += this.renderer.paragraph(this.parseInline(token.tokens));
  1908. continue;
  1909. }
  1910. case 'text':
  1911. {
  1912. body = token.tokens ? this.parseInline(token.tokens) : token.text;
  1913. while (i + 1 < l && tokens[i + 1].type === 'text') {
  1914. token = tokens[++i];
  1915. body += '\n' + (token.tokens ? this.parseInline(token.tokens) : token.text);
  1916. }
  1917. out += top ? this.renderer.paragraph(body) : body;
  1918. continue;
  1919. }
  1920. default:
  1921. {
  1922. var errMsg = 'Token with "' + token.type + '" type was not found.';
  1923. if (this.options.silent) {
  1924. console.error(errMsg);
  1925. return;
  1926. } else {
  1927. throw new Error(errMsg);
  1928. }
  1929. }
  1930. }
  1931. }
  1932. return out;
  1933. }
  1934. /**
  1935. * Parse Inline Tokens
  1936. */
  1937. ;
  1938. _proto.parseInline = function parseInline(tokens, renderer) {
  1939. renderer = renderer || this.renderer;
  1940. var out = '',
  1941. i,
  1942. token;
  1943. var l = tokens.length;
  1944. for (i = 0; i < l; i++) {
  1945. token = tokens[i];
  1946. switch (token.type) {
  1947. case 'escape':
  1948. {
  1949. out += renderer.text(token.text);
  1950. break;
  1951. }
  1952. case 'html':
  1953. {
  1954. out += renderer.html(token.text);
  1955. break;
  1956. }
  1957. case 'link':
  1958. {
  1959. out += renderer.link(token.href, token.title, this.parseInline(token.tokens, renderer));
  1960. break;
  1961. }
  1962. case 'image':
  1963. {
  1964. out += renderer.image(token.href, token.title, token.text);
  1965. break;
  1966. }
  1967. case 'strong':
  1968. {
  1969. out += renderer.strong(this.parseInline(token.tokens, renderer));
  1970. break;
  1971. }
  1972. case 'em':
  1973. {
  1974. out += renderer.em(this.parseInline(token.tokens, renderer));
  1975. break;
  1976. }
  1977. case 'codespan':
  1978. {
  1979. out += renderer.codespan(token.text);
  1980. break;
  1981. }
  1982. case 'br':
  1983. {
  1984. out += renderer.br();
  1985. break;
  1986. }
  1987. case 'del':
  1988. {
  1989. out += renderer.del(this.parseInline(token.tokens, renderer));
  1990. break;
  1991. }
  1992. case 'text':
  1993. {
  1994. out += renderer.text(token.text);
  1995. break;
  1996. }
  1997. default:
  1998. {
  1999. var errMsg = 'Token with "' + token.type + '" type was not found.';
  2000. if (this.options.silent) {
  2001. console.error(errMsg);
  2002. return;
  2003. } else {
  2004. throw new Error(errMsg);
  2005. }
  2006. }
  2007. }
  2008. }
  2009. return out;
  2010. };
  2011. return Parser;
  2012. }();
  2013. var merge$2 = helpers.merge,
  2014. checkSanitizeDeprecation$1 = helpers.checkSanitizeDeprecation,
  2015. escape$2 = helpers.escape;
  2016. var getDefaults = defaults.getDefaults,
  2017. changeDefaults = defaults.changeDefaults,
  2018. defaults$5 = defaults.defaults;
  2019. /**
  2020. * Marked
  2021. */
  2022. function marked(src, opt, callback) {
  2023. // throw error in case of non string input
  2024. if (typeof src === 'undefined' || src === null) {
  2025. throw new Error('marked(): input parameter is undefined or null');
  2026. }
  2027. if (typeof src !== 'string') {
  2028. throw new Error('marked(): input parameter is of type ' + Object.prototype.toString.call(src) + ', string expected');
  2029. }
  2030. if (typeof opt === 'function') {
  2031. callback = opt;
  2032. opt = null;
  2033. }
  2034. opt = merge$2({}, marked.defaults, opt || {});
  2035. checkSanitizeDeprecation$1(opt);
  2036. if (callback) {
  2037. var highlight = opt.highlight;
  2038. var tokens;
  2039. try {
  2040. tokens = Lexer_1.lex(src, opt);
  2041. } catch (e) {
  2042. return callback(e);
  2043. }
  2044. var done = function done(err) {
  2045. var out;
  2046. if (!err) {
  2047. try {
  2048. out = Parser_1.parse(tokens, opt);
  2049. } catch (e) {
  2050. err = e;
  2051. }
  2052. }
  2053. opt.highlight = highlight;
  2054. return err ? callback(err) : callback(null, out);
  2055. };
  2056. if (!highlight || highlight.length < 3) {
  2057. return done();
  2058. }
  2059. delete opt.highlight;
  2060. if (!tokens.length) return done();
  2061. var pending = 0;
  2062. marked.walkTokens(tokens, function (token) {
  2063. if (token.type === 'code') {
  2064. pending++;
  2065. setTimeout(function () {
  2066. highlight(token.text, token.lang, function (err, code) {
  2067. if (err) {
  2068. return done(err);
  2069. }
  2070. if (code != null && code !== token.text) {
  2071. token.text = code;
  2072. token.escaped = true;
  2073. }
  2074. pending--;
  2075. if (pending === 0) {
  2076. done();
  2077. }
  2078. });
  2079. }, 0);
  2080. }
  2081. });
  2082. if (pending === 0) {
  2083. done();
  2084. }
  2085. return;
  2086. }
  2087. try {
  2088. var _tokens = Lexer_1.lex(src, opt);
  2089. if (opt.walkTokens) {
  2090. marked.walkTokens(_tokens, opt.walkTokens);
  2091. }
  2092. return Parser_1.parse(_tokens, opt);
  2093. } catch (e) {
  2094. e.message += '\nPlease report this to https://github.com/markedjs/marked.';
  2095. if (opt.silent) {
  2096. return '<p>An error occurred:</p><pre>' + escape$2(e.message + '', true) + '</pre>';
  2097. }
  2098. throw e;
  2099. }
  2100. }
  2101. /**
  2102. * Options
  2103. */
  2104. marked.options = marked.setOptions = function (opt) {
  2105. merge$2(marked.defaults, opt);
  2106. changeDefaults(marked.defaults);
  2107. return marked;
  2108. };
  2109. marked.getDefaults = getDefaults;
  2110. marked.defaults = defaults$5;
  2111. /**
  2112. * Use Extension
  2113. */
  2114. marked.use = function (extension) {
  2115. var opts = merge$2({}, extension);
  2116. if (extension.renderer) {
  2117. (function () {
  2118. var renderer = marked.defaults.renderer || new Renderer_1();
  2119. var _loop = function _loop(prop) {
  2120. var prevRenderer = renderer[prop];
  2121. renderer[prop] = function () {
  2122. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  2123. args[_key] = arguments[_key];
  2124. }
  2125. var ret = extension.renderer[prop].apply(renderer, args);
  2126. if (ret === false) {
  2127. ret = prevRenderer.apply(renderer, args);
  2128. }
  2129. return ret;
  2130. };
  2131. };
  2132. for (var prop in extension.renderer) {
  2133. _loop(prop);
  2134. }
  2135. opts.renderer = renderer;
  2136. })();
  2137. }
  2138. if (extension.tokenizer) {
  2139. (function () {
  2140. var tokenizer = marked.defaults.tokenizer || new Tokenizer_1();
  2141. var _loop2 = function _loop2(prop) {
  2142. var prevTokenizer = tokenizer[prop];
  2143. tokenizer[prop] = function () {
  2144. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  2145. args[_key2] = arguments[_key2];
  2146. }
  2147. var ret = extension.tokenizer[prop].apply(tokenizer, args);
  2148. if (ret === false) {
  2149. ret = prevTokenizer.apply(tokenizer, args);
  2150. }
  2151. return ret;
  2152. };
  2153. };
  2154. for (var prop in extension.tokenizer) {
  2155. _loop2(prop);
  2156. }
  2157. opts.tokenizer = tokenizer;
  2158. })();
  2159. }
  2160. if (extension.walkTokens) {
  2161. var walkTokens = marked.defaults.walkTokens;
  2162. opts.walkTokens = function (token) {
  2163. extension.walkTokens(token);
  2164. if (walkTokens) {
  2165. walkTokens(token);
  2166. }
  2167. };
  2168. }
  2169. marked.setOptions(opts);
  2170. };
  2171. /**
  2172. * Run callback for every token
  2173. */
  2174. marked.walkTokens = function (tokens, callback) {
  2175. for (var _iterator = _createForOfIteratorHelperLoose(tokens), _step; !(_step = _iterator()).done;) {
  2176. var token = _step.value;
  2177. callback(token);
  2178. switch (token.type) {
  2179. case 'table':
  2180. {
  2181. for (var _iterator2 = _createForOfIteratorHelperLoose(token.tokens.header), _step2; !(_step2 = _iterator2()).done;) {
  2182. var cell = _step2.value;
  2183. marked.walkTokens(cell, callback);
  2184. }
  2185. for (var _iterator3 = _createForOfIteratorHelperLoose(token.tokens.cells), _step3; !(_step3 = _iterator3()).done;) {
  2186. var row = _step3.value;
  2187. for (var _iterator4 = _createForOfIteratorHelperLoose(row), _step4; !(_step4 = _iterator4()).done;) {
  2188. var _cell = _step4.value;
  2189. marked.walkTokens(_cell, callback);
  2190. }
  2191. }
  2192. break;
  2193. }
  2194. case 'list':
  2195. {
  2196. marked.walkTokens(token.items, callback);
  2197. break;
  2198. }
  2199. default:
  2200. {
  2201. if (token.tokens) {
  2202. marked.walkTokens(token.tokens, callback);
  2203. }
  2204. }
  2205. }
  2206. }
  2207. };
  2208. /**
  2209. * Parse Inline
  2210. */
  2211. marked.parseInline = function (src, opt) {
  2212. // throw error in case of non string input
  2213. if (typeof src === 'undefined' || src === null) {
  2214. throw new Error('marked.parseInline(): input parameter is undefined or null');
  2215. }
  2216. if (typeof src !== 'string') {
  2217. throw new Error('marked.parseInline(): input parameter is of type ' + Object.prototype.toString.call(src) + ', string expected');
  2218. }
  2219. opt = merge$2({}, marked.defaults, opt || {});
  2220. checkSanitizeDeprecation$1(opt);
  2221. try {
  2222. var tokens = Lexer_1.lexInline(src, opt);
  2223. if (opt.walkTokens) {
  2224. marked.walkTokens(tokens, opt.walkTokens);
  2225. }
  2226. return Parser_1.parseInline(tokens, opt);
  2227. } catch (e) {
  2228. e.message += '\nPlease report this to https://github.com/markedjs/marked.';
  2229. if (opt.silent) {
  2230. return '<p>An error occurred:</p><pre>' + escape$2(e.message + '', true) + '</pre>';
  2231. }
  2232. throw e;
  2233. }
  2234. };
  2235. /**
  2236. * Expose
  2237. */
  2238. marked.Parser = Parser_1;
  2239. marked.parser = Parser_1.parse;
  2240. marked.Renderer = Renderer_1;
  2241. marked.TextRenderer = TextRenderer_1;
  2242. marked.Lexer = Lexer_1;
  2243. marked.lexer = Lexer_1.lex;
  2244. marked.Tokenizer = Tokenizer_1;
  2245. marked.Slugger = Slugger_1;
  2246. marked.parse = marked;
  2247. var marked_1 = marked;
  2248. return marked_1;
  2249. })));