marked.cjs 92 KB

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