marked.js 73 KB

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