marked.js 73 KB

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