marked 7.0.4 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/marked.umd.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * marked v7.0.4 - a markdown parser
2
+ * marked v8.0.0 - a markdown parser
3
3
  * Copyright (c) 2011-2023, Christopher Jeffrey. (MIT Licensed)
4
4
  * https://github.com/markedjs/marked
5
5
  */
@@ -21,25 +21,15 @@
21
21
  function _getDefaults() {
22
22
  return {
23
23
  async: false,
24
- baseUrl: null,
25
24
  breaks: false,
26
25
  extensions: null,
27
26
  gfm: true,
28
- headerIds: false,
29
- headerPrefix: '',
30
- highlight: null,
31
27
  hooks: null,
32
- langPrefix: 'language-',
33
- mangle: false,
34
28
  pedantic: false,
35
29
  renderer: null,
36
- sanitize: false,
37
- sanitizer: null,
38
30
  silent: false,
39
- smartypants: false,
40
31
  tokenizer: null,
41
- walkTokens: null,
42
- xhtml: false
32
+ walkTokens: null
43
33
  };
44
34
  }
45
35
  exports.defaults = _getDefaults();
@@ -107,26 +97,7 @@
107
97
  };
108
98
  return obj;
109
99
  }
110
- const nonWordAndColonTest = /[^\w:]/g;
111
- const originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
112
- function cleanUrl(sanitize, base, href) {
113
- if (sanitize) {
114
- let prot;
115
- try {
116
- prot = decodeURIComponent(unescape(href))
117
- .replace(nonWordAndColonTest, '')
118
- .toLowerCase();
119
- }
120
- catch (e) {
121
- return null;
122
- }
123
- if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
124
- return null;
125
- }
126
- }
127
- if (base && !originIndependentUrl.test(href)) {
128
- href = resolveUrl(base, href);
129
- }
100
+ function cleanUrl(href) {
130
101
  try {
131
102
  href = encodeURI(href).replace(/%25/g, '%');
132
103
  }
@@ -135,40 +106,6 @@
135
106
  }
136
107
  return href;
137
108
  }
138
- const baseUrls = {};
139
- const justDomain = /^[^:]+:\/*[^/]*$/;
140
- const protocol = /^([^:]+:)[\s\S]*$/;
141
- const domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
142
- function resolveUrl(base, href) {
143
- if (!baseUrls[' ' + base]) {
144
- // we can ignore everything in base after the last slash of its path component,
145
- // but we might need to add _that_
146
- // https://tools.ietf.org/html/rfc3986#section-3
147
- if (justDomain.test(base)) {
148
- baseUrls[' ' + base] = base + '/';
149
- }
150
- else {
151
- baseUrls[' ' + base] = rtrim(base, '/', true);
152
- }
153
- }
154
- base = baseUrls[' ' + base];
155
- const relativeBase = base.indexOf(':') === -1;
156
- if (href.substring(0, 2) === '//') {
157
- if (relativeBase) {
158
- return href;
159
- }
160
- return base.replace(protocol, '$1') + href;
161
- }
162
- else if (href.charAt(0) === '/') {
163
- if (relativeBase) {
164
- return href;
165
- }
166
- return base.replace(domain, '$1') + href;
167
- }
168
- else {
169
- return base + href;
170
- }
171
- }
172
109
  const noopTest = { exec: () => null };
173
110
  function splitCells(tableRow, count) {
174
111
  // ensure that every cell-delimiting pipe has a space
@@ -262,35 +199,6 @@
262
199
  }
263
200
  return -1;
264
201
  }
265
- function checkDeprecations(opt, callback) {
266
- if (!opt || opt.silent) {
267
- return;
268
- }
269
- if (callback) {
270
- console.warn('marked(): callback is deprecated since version 5.0.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/using_pro#async');
271
- }
272
- if (opt.sanitize || opt.sanitizer) {
273
- 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');
274
- }
275
- if (opt.highlight || opt.langPrefix !== 'language-') {
276
- console.warn('marked(): highlight and langPrefix parameters are deprecated since version 5.0.0, should not be used and will be removed in the future. Instead use https://www.npmjs.com/package/marked-highlight.');
277
- }
278
- if (opt.mangle) {
279
- console.warn('marked(): mangle parameter is enabled by default, but is deprecated since version 5.0.0, and will be removed in the future. To clear this warning, install https://www.npmjs.com/package/marked-mangle, or disable by setting `{mangle: false}`.');
280
- }
281
- if (opt.baseUrl) {
282
- console.warn('marked(): baseUrl parameter is deprecated since version 5.0.0, should not be used and will be removed in the future. Instead use https://www.npmjs.com/package/marked-base-url.');
283
- }
284
- if (opt.smartypants) {
285
- console.warn('marked(): smartypants parameter is deprecated since version 5.0.0, should not be used and will be removed in the future. Instead use https://www.npmjs.com/package/marked-smartypants.');
286
- }
287
- if (opt.xhtml) {
288
- console.warn('marked(): xhtml parameter is deprecated since version 5.0.0, should not be used and will be removed in the future. Instead use https://www.npmjs.com/package/marked-xhtml.');
289
- }
290
- if (opt.headerIds || opt.headerPrefix) {
291
- console.warn('marked(): headerIds and headerPrefix parameters enabled by default, but are deprecated since version 5.0.0, and will be removed in the future. To clear this warning, install https://www.npmjs.com/package/marked-gfm-heading-id, or disable by setting `{headerIds: false}`.');
292
- }
293
- }
294
202
 
295
203
  function outputLink(cap, link, raw, lexer) {
296
204
  const href = link.href;
@@ -607,17 +515,9 @@
607
515
  type: 'html',
608
516
  block: true,
609
517
  raw: cap[0],
610
- pre: !this.options.sanitizer
611
- && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
518
+ pre: cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style',
612
519
  text: cap[0]
613
520
  };
614
- if (this.options.sanitize) {
615
- const text = this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0]);
616
- const paragraph = token;
617
- paragraph.type = 'paragraph';
618
- paragraph.text = text;
619
- paragraph.tokens = this.lexer.inline(text);
620
- }
621
521
  return token;
622
522
  }
623
523
  }
@@ -755,18 +655,12 @@
755
655
  this.lexer.state.inRawBlock = false;
756
656
  }
757
657
  return {
758
- type: this.options.sanitize
759
- ? 'text'
760
- : 'html',
658
+ type: 'html',
761
659
  raw: cap[0],
762
660
  inLink: this.lexer.state.inLink,
763
661
  inRawBlock: this.lexer.state.inRawBlock,
764
662
  block: false,
765
- text: this.options.sanitize
766
- ? (this.options.sanitizer
767
- ? this.options.sanitizer(cap[0])
768
- : escape(cap[0]))
769
- : cap[0]
663
+ text: cap[0]
770
664
  };
771
665
  }
772
666
  }
@@ -937,12 +831,12 @@
937
831
  };
938
832
  }
939
833
  }
940
- autolink(src, mangle) {
834
+ autolink(src) {
941
835
  const cap = this.rules.inline.autolink.exec(src);
942
836
  if (cap) {
943
837
  let text, href;
944
838
  if (cap[2] === '@') {
945
- text = escape(this.options.mangle ? mangle(cap[1]) : cap[1]);
839
+ text = escape(cap[1]);
946
840
  href = 'mailto:' + text;
947
841
  }
948
842
  else {
@@ -964,12 +858,12 @@
964
858
  };
965
859
  }
966
860
  }
967
- url(src, mangle) {
861
+ url(src) {
968
862
  let cap;
969
863
  if (cap = this.rules.inline.url.exec(src)) {
970
864
  let text, href;
971
865
  if (cap[2] === '@') {
972
- text = escape(this.options.mangle ? mangle(cap[0]) : cap[0]);
866
+ text = escape(cap[0]);
973
867
  href = 'mailto:' + text;
974
868
  }
975
869
  else {
@@ -1002,15 +896,15 @@
1002
896
  };
1003
897
  }
1004
898
  }
1005
- inlineText(src, smartypants) {
899
+ inlineText(src) {
1006
900
  const cap = this.rules.inline.text.exec(src);
1007
901
  if (cap) {
1008
902
  let text;
1009
903
  if (this.lexer.state.inRawBlock) {
1010
- text = this.options.sanitize ? (this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0])) : cap[0];
904
+ text = cap[0];
1011
905
  }
1012
906
  else {
1013
- text = escape(this.options.smartypants ? smartypants(cap[0]) : cap[0]);
907
+ text = escape(cap[0]);
1014
908
  }
1015
909
  return {
1016
910
  type: 'text',
@@ -1298,39 +1192,6 @@
1298
1192
  .getRegex()
1299
1193
  };
1300
1194
 
1301
- /**
1302
- * smartypants text replacement
1303
- */
1304
- function smartypants(text) {
1305
- return text
1306
- // em-dashes
1307
- .replace(/---/g, '\u2014')
1308
- // en-dashes
1309
- .replace(/--/g, '\u2013')
1310
- // opening singles
1311
- .replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
1312
- // closing singles & apostrophes
1313
- .replace(/'/g, '\u2019')
1314
- // opening doubles
1315
- .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
1316
- // closing doubles
1317
- .replace(/"/g, '\u201d')
1318
- // ellipses
1319
- .replace(/\.{3}/g, '\u2026');
1320
- }
1321
- /**
1322
- * mangle email addresses
1323
- */
1324
- function mangle(text) {
1325
- let out = '';
1326
- for (let i = 0; i < text.length; i++) {
1327
- const ch = Math.random() > 0.5
1328
- ? 'x' + text.charCodeAt(i).toString(16)
1329
- : text.charCodeAt(i).toString();
1330
- out += '&#' + ch + ';';
1331
- }
1332
- return out;
1333
- }
1334
1195
  /**
1335
1196
  * Block Lexer
1336
1197
  */
@@ -1704,13 +1565,13 @@
1704
1565
  continue;
1705
1566
  }
1706
1567
  // autolink
1707
- if (token = this.tokenizer.autolink(src, mangle)) {
1568
+ if (token = this.tokenizer.autolink(src)) {
1708
1569
  src = src.substring(token.raw.length);
1709
1570
  tokens.push(token);
1710
1571
  continue;
1711
1572
  }
1712
1573
  // url (gfm)
1713
- if (!this.state.inLink && (token = this.tokenizer.url(src, mangle))) {
1574
+ if (!this.state.inLink && (token = this.tokenizer.url(src))) {
1714
1575
  src = src.substring(token.raw.length);
1715
1576
  tokens.push(token);
1716
1577
  continue;
@@ -1732,7 +1593,7 @@
1732
1593
  cutSrc = src.substring(0, startIndex + 1);
1733
1594
  }
1734
1595
  }
1735
- if (token = this.tokenizer.inlineText(cutSrc, smartypants)) {
1596
+ if (token = this.tokenizer.inlineText(cutSrc)) {
1736
1597
  src = src.substring(token.raw.length);
1737
1598
  if (token.raw.slice(-1) !== '_') { // Track prevChar before string of ____ started
1738
1599
  prevChar = token.raw.slice(-1);
@@ -1773,21 +1634,13 @@
1773
1634
  }
1774
1635
  code(code, infostring, escaped) {
1775
1636
  const lang = (infostring || '').match(/^\S*/)?.[0];
1776
- if (this.options.highlight) {
1777
- const out = this.options.highlight(code, lang);
1778
- if (out != null && out !== code) {
1779
- escaped = true;
1780
- code = out;
1781
- }
1782
- }
1783
1637
  code = code.replace(/\n$/, '') + '\n';
1784
1638
  if (!lang) {
1785
1639
  return '<pre><code>'
1786
1640
  + (escaped ? code : escape(code, true))
1787
1641
  + '</code></pre>\n';
1788
1642
  }
1789
- return '<pre><code class="'
1790
- + this.options.langPrefix
1643
+ return '<pre><code class="language-'
1791
1644
  + escape(lang)
1792
1645
  + '">'
1793
1646
  + (escaped ? code : escape(code, true))
@@ -1799,16 +1652,12 @@
1799
1652
  html(html, block) {
1800
1653
  return html;
1801
1654
  }
1802
- heading(text, level, raw, slugger) {
1803
- if (this.options.headerIds) {
1804
- const id = this.options.headerPrefix + slugger.slug(raw);
1805
- return `<h${level} id="${id}">${text}</h${level}>\n`;
1806
- }
1655
+ heading(text, level, raw) {
1807
1656
  // ignore IDs
1808
1657
  return `<h${level}>${text}</h${level}>\n`;
1809
1658
  }
1810
1659
  hr() {
1811
- return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
1660
+ return '<hr>\n';
1812
1661
  }
1813
1662
  list(body, ordered, start) {
1814
1663
  const type = ordered ? 'ol' : 'ul';
@@ -1821,9 +1670,7 @@
1821
1670
  checkbox(checked) {
1822
1671
  return '<input '
1823
1672
  + (checked ? 'checked="" ' : '')
1824
- + 'disabled="" type="checkbox"'
1825
- + (this.options.xhtml ? ' /' : '')
1826
- + '> ';
1673
+ + 'disabled="" type="checkbox">';
1827
1674
  }
1828
1675
  paragraph(text) {
1829
1676
  return `<p>${text}</p>\n`;
@@ -1861,13 +1708,13 @@
1861
1708
  return `<code>${text}</code>`;
1862
1709
  }
1863
1710
  br() {
1864
- return this.options.xhtml ? '<br/>' : '<br>';
1711
+ return '<br>';
1865
1712
  }
1866
1713
  del(text) {
1867
1714
  return `<del>${text}</del>`;
1868
1715
  }
1869
1716
  link(href, title, text) {
1870
- const cleanHref = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
1717
+ const cleanHref = cleanUrl(href);
1871
1718
  if (cleanHref === null) {
1872
1719
  return text;
1873
1720
  }
@@ -1880,7 +1727,7 @@
1880
1727
  return out;
1881
1728
  }
1882
1729
  image(href, title, text) {
1883
- const cleanHref = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
1730
+ const cleanHref = cleanUrl(href);
1884
1731
  if (cleanHref === null) {
1885
1732
  return text;
1886
1733
  }
@@ -1889,7 +1736,7 @@
1889
1736
  if (title) {
1890
1737
  out += ` title="${title}"`;
1891
1738
  }
1892
- out += this.options.xhtml ? '/>' : '>';
1739
+ out += '>';
1893
1740
  return out;
1894
1741
  }
1895
1742
  text(text) {
@@ -1932,52 +1779,6 @@
1932
1779
  }
1933
1780
  }
1934
1781
 
1935
- /**
1936
- * Slugger generates header id
1937
- */
1938
- class _Slugger {
1939
- seen;
1940
- constructor() {
1941
- this.seen = {};
1942
- }
1943
- serialize(value) {
1944
- return value
1945
- .toLowerCase()
1946
- .trim()
1947
- // remove html tags
1948
- .replace(/<[!\/a-z].*?>/ig, '')
1949
- // remove unwanted chars
1950
- .replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '')
1951
- .replace(/\s/g, '-');
1952
- }
1953
- /**
1954
- * Finds the next safe (unique) slug to use
1955
- */
1956
- getNextSafeSlug(originalSlug, isDryRun) {
1957
- let slug = originalSlug;
1958
- let occurenceAccumulator = 0;
1959
- if (this.seen.hasOwnProperty(slug)) {
1960
- occurenceAccumulator = this.seen[originalSlug];
1961
- do {
1962
- occurenceAccumulator++;
1963
- slug = originalSlug + '-' + occurenceAccumulator;
1964
- } while (this.seen.hasOwnProperty(slug));
1965
- }
1966
- if (!isDryRun) {
1967
- this.seen[originalSlug] = occurenceAccumulator;
1968
- this.seen[slug] = 0;
1969
- }
1970
- return slug;
1971
- }
1972
- /**
1973
- * Convert string to unique id
1974
- */
1975
- slug(value, options = {}) {
1976
- const slug = this.serialize(value);
1977
- return this.getNextSafeSlug(slug, options.dryrun);
1978
- }
1979
- }
1980
-
1981
1782
  /**
1982
1783
  * Parsing & Compiling
1983
1784
  */
@@ -1985,14 +1786,12 @@
1985
1786
  options;
1986
1787
  renderer;
1987
1788
  textRenderer;
1988
- slugger;
1989
1789
  constructor(options) {
1990
1790
  this.options = options || exports.defaults;
1991
1791
  this.options.renderer = this.options.renderer || new _Renderer();
1992
1792
  this.renderer = this.options.renderer;
1993
1793
  this.renderer.options = this.options;
1994
1794
  this.textRenderer = new _TextRenderer();
1995
- this.slugger = new _Slugger();
1996
1795
  }
1997
1796
  /**
1998
1797
  * Static Parse Method
@@ -2034,7 +1833,7 @@
2034
1833
  }
2035
1834
  case 'heading': {
2036
1835
  const headingToken = token;
2037
- out += this.renderer.heading(this.parseInline(headingToken.tokens), headingToken.depth, unescape(this.parseInline(headingToken.tokens, this.textRenderer)), this.slugger);
1836
+ out += this.renderer.heading(this.parseInline(headingToken.tokens), headingToken.depth, unescape(this.parseInline(headingToken.tokens, this.textRenderer)));
2038
1837
  continue;
2039
1838
  }
2040
1839
  case 'code': {
@@ -2257,7 +2056,6 @@
2257
2056
  Lexer = _Lexer;
2258
2057
  lexer = _Lexer.lex;
2259
2058
  Tokenizer = _Tokenizer;
2260
- Slugger = _Slugger;
2261
2059
  Hooks = _Hooks;
2262
2060
  constructor(...args) {
2263
2061
  this.use(...args);
@@ -2454,12 +2252,8 @@
2454
2252
  return this;
2455
2253
  }
2456
2254
  #parseMarkdown(lexer, parser) {
2457
- return (src, optOrCallback, callback) => {
2458
- if (typeof optOrCallback === 'function') {
2459
- callback = optOrCallback;
2460
- optOrCallback = null;
2461
- }
2462
- const origOpt = { ...optOrCallback };
2255
+ return (src, options) => {
2256
+ const origOpt = { ...options };
2463
2257
  const opt = { ...this.defaults, ...origOpt };
2464
2258
  // Show warning if an extension set async to true but the parse was called with async: false
2465
2259
  if (this.defaults.async === true && origOpt.async === false) {
@@ -2468,7 +2262,7 @@
2468
2262
  }
2469
2263
  opt.async = true;
2470
2264
  }
2471
- const throwError = this.#onError(!!opt.silent, !!opt.async, callback);
2265
+ const throwError = this.#onError(!!opt.silent, !!opt.async);
2472
2266
  // throw error in case of non string input
2473
2267
  if (typeof src === 'undefined' || src === null) {
2474
2268
  return throwError(new Error('marked(): input parameter is undefined or null'));
@@ -2477,76 +2271,9 @@
2477
2271
  return throwError(new Error('marked(): input parameter is of type '
2478
2272
  + Object.prototype.toString.call(src) + ', string expected'));
2479
2273
  }
2480
- checkDeprecations(opt, callback);
2481
2274
  if (opt.hooks) {
2482
2275
  opt.hooks.options = opt;
2483
2276
  }
2484
- if (callback) {
2485
- const resultCallback = callback;
2486
- const highlight = opt.highlight;
2487
- let tokens;
2488
- try {
2489
- if (opt.hooks) {
2490
- src = opt.hooks.preprocess(src);
2491
- }
2492
- tokens = lexer(src, opt);
2493
- }
2494
- catch (e) {
2495
- return throwError(e);
2496
- }
2497
- const done = (err) => {
2498
- let out;
2499
- if (!err) {
2500
- try {
2501
- if (opt.walkTokens) {
2502
- this.walkTokens(tokens, opt.walkTokens);
2503
- }
2504
- out = parser(tokens, opt);
2505
- if (opt.hooks) {
2506
- out = opt.hooks.postprocess(out);
2507
- }
2508
- }
2509
- catch (e) {
2510
- err = e;
2511
- }
2512
- }
2513
- opt.highlight = highlight;
2514
- return err
2515
- ? throwError(err)
2516
- : resultCallback(null, out);
2517
- };
2518
- if (!highlight || highlight.length < 3) {
2519
- return done();
2520
- }
2521
- delete opt.highlight;
2522
- if (!tokens.length)
2523
- return done();
2524
- let pending = 0;
2525
- this.walkTokens(tokens, (token) => {
2526
- if (token.type === 'code') {
2527
- pending++;
2528
- setTimeout(() => {
2529
- highlight(token.text, token.lang, (err, code) => {
2530
- if (err) {
2531
- return done(err);
2532
- }
2533
- if (code != null && code !== token.text) {
2534
- token.text = code;
2535
- token.escaped = true;
2536
- }
2537
- pending--;
2538
- if (pending === 0) {
2539
- done();
2540
- }
2541
- });
2542
- }, 0);
2543
- }
2544
- });
2545
- if (pending === 0) {
2546
- done();
2547
- }
2548
- return;
2549
- }
2550
2277
  if (opt.async) {
2551
2278
  return Promise.resolve(opt.hooks ? opt.hooks.preprocess(src) : src)
2552
2279
  .then(src => lexer(src, opt))
@@ -2574,7 +2301,7 @@
2574
2301
  }
2575
2302
  };
2576
2303
  }
2577
- #onError(silent, async, callback) {
2304
+ #onError(silent, async) {
2578
2305
  return (e) => {
2579
2306
  e.message += '\nPlease report this to https://github.com/markedjs/marked.';
2580
2307
  if (silent) {
@@ -2584,27 +2311,19 @@
2584
2311
  if (async) {
2585
2312
  return Promise.resolve(msg);
2586
2313
  }
2587
- if (callback) {
2588
- callback(null, msg);
2589
- return;
2590
- }
2591
2314
  return msg;
2592
2315
  }
2593
2316
  if (async) {
2594
2317
  return Promise.reject(e);
2595
2318
  }
2596
- if (callback) {
2597
- callback(e);
2598
- return;
2599
- }
2600
2319
  throw e;
2601
2320
  };
2602
2321
  }
2603
2322
  }
2604
2323
 
2605
2324
  const markedInstance = new Marked();
2606
- function marked(src, opt, callback) {
2607
- return markedInstance.parse(src, opt, callback);
2325
+ function marked(src, opt) {
2326
+ return markedInstance.parse(src, opt);
2608
2327
  }
2609
2328
  /**
2610
2329
  * Sets the default options.
@@ -2656,7 +2375,6 @@
2656
2375
  marked.Lexer = _Lexer;
2657
2376
  marked.lexer = _Lexer.lex;
2658
2377
  marked.Tokenizer = _Tokenizer;
2659
- marked.Slugger = _Slugger;
2660
2378
  marked.Hooks = _Hooks;
2661
2379
  marked.parse = marked;
2662
2380
  const options = marked.options;
@@ -2673,7 +2391,6 @@
2673
2391
  exports.Marked = Marked;
2674
2392
  exports.Parser = _Parser;
2675
2393
  exports.Renderer = _Renderer;
2676
- exports.Slugger = _Slugger;
2677
2394
  exports.TextRenderer = _TextRenderer;
2678
2395
  exports.Tokenizer = _Tokenizer;
2679
2396
  exports.getDefaults = _getDefaults;