marked.js 86 KB

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