marked.js 93 KB

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