098965c965a22c392d54eb167a82785f96bece0c0ca96dfcb479b2ca092473678d81c5e155be6643cdbdb7446583aa0face1507528dfec9e45800675df1fab 96 KB

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