marked.js 86 KB

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