marked.umd.js 92 KB

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