marked.umd.js 98 KB

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