marked.esm.js 68 KB

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