marked.umd.js 93 KB

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