You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2703 lines
78 KiB

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