marked.cjs 88 KB

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