marked 4.0.12 → 4.0.15

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/bin/marked.js CHANGED
@@ -188,6 +188,9 @@ function getStdin() {
188
188
  });
189
189
  }
190
190
 
191
+ /**
192
+ * @param {string} text
193
+ */
191
194
  function camelize(text) {
192
195
  return text.replace(/(\w)-(\w)/g, function(_, a, b) {
193
196
  return a + b.toUpperCase();
package/lib/marked.cjs CHANGED
@@ -131,6 +131,10 @@ function escape(html, encode) {
131
131
  return html;
132
132
  }
133
133
  var unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
134
+ /**
135
+ * @param {string} html
136
+ */
137
+
134
138
  function unescape(html) {
135
139
  // explicitly match decimal, hex, and named HTML entities
136
140
  return html.replace(unescapeTest, function (_, n) {
@@ -145,8 +149,13 @@ function unescape(html) {
145
149
  });
146
150
  }
147
151
  var caret = /(^|[^\[])\^/g;
152
+ /**
153
+ * @param {string | RegExp} regex
154
+ * @param {string} opt
155
+ */
156
+
148
157
  function edit(regex, opt) {
149
- regex = regex.source || regex;
158
+ regex = typeof regex === 'string' ? regex : regex.source;
150
159
  opt = opt || '';
151
160
  var obj = {
152
161
  replace: function replace(name, val) {
@@ -163,6 +172,12 @@ function edit(regex, opt) {
163
172
  }
164
173
  var nonWordAndColonTest = /[^\w:]/g;
165
174
  var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
175
+ /**
176
+ * @param {boolean} sanitize
177
+ * @param {string} base
178
+ * @param {string} href
179
+ */
180
+
166
181
  function cleanUrl(sanitize, base, href) {
167
182
  if (sanitize) {
168
183
  var prot;
@@ -194,6 +209,11 @@ var baseUrls = {};
194
209
  var justDomain = /^[^:]+:\/*[^/]*$/;
195
210
  var protocol = /^([^:]+:)[\s\S]*$/;
196
211
  var domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
212
+ /**
213
+ * @param {string} base
214
+ * @param {string} href
215
+ */
216
+
197
217
  function resolveUrl(base, href) {
198
218
  if (!baseUrls[' ' + base]) {
199
219
  // we can ignore everything in base after the last slash of its path component,
@@ -290,9 +310,15 @@ function splitCells(tableRow, count) {
290
310
  }
291
311
 
292
312
  return cells;
293
- } // Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
294
- // /c*$/ is vulnerable to REDOS.
295
- // invert: Remove suffix of non-c chars instead. Default falsey.
313
+ }
314
+ /**
315
+ * Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
316
+ * /c*$/ is vulnerable to REDOS.
317
+ *
318
+ * @param {string} str
319
+ * @param {string} c
320
+ * @param {boolean} invert Remove suffix of non-c chars instead. Default falsey.
321
+ */
296
322
 
297
323
  function rtrim(str, c, invert) {
298
324
  var l = str.length;
@@ -316,7 +342,7 @@ function rtrim(str, c, invert) {
316
342
  }
317
343
  }
318
344
 
319
- return str.substr(0, l - suffLen);
345
+ return str.slice(0, l - suffLen);
320
346
  }
321
347
  function findClosingBracket(str, b) {
322
348
  if (str.indexOf(b[1]) === -1) {
@@ -349,6 +375,11 @@ function checkSanitizeDeprecation(opt) {
349
375
  }
350
376
  } // copied from https://stackoverflow.com/a/5450113/806777
351
377
 
378
+ /**
379
+ * @param {string} pattern
380
+ * @param {number} count
381
+ */
382
+
352
383
  function repeatString(pattern, count) {
353
384
  if (count < 1) {
354
385
  return '';
@@ -385,15 +416,15 @@ function outputLink(cap, link, raw, lexer) {
385
416
  };
386
417
  lexer.state.inLink = false;
387
418
  return token;
388
- } else {
389
- return {
390
- type: 'image',
391
- raw: raw,
392
- href: href,
393
- title: title,
394
- text: escape(text)
395
- };
396
419
  }
420
+
421
+ return {
422
+ type: 'image',
423
+ raw: raw,
424
+ href: href,
425
+ title: title,
426
+ text: escape(text)
427
+ };
397
428
  }
398
429
 
399
430
  function indentCodeCompensation(raw, text) {
@@ -516,7 +547,7 @@ var Tokenizer = /*#__PURE__*/function () {
516
547
  var cap = this.rules.block.blockquote.exec(src);
517
548
 
518
549
  if (cap) {
519
- var text = cap[0].replace(/^ *> ?/gm, '');
550
+ var text = cap[0].replace(/^ *>[ \t]?/gm, '');
520
551
  return {
521
552
  type: 'blockquote',
522
553
  raw: cap[0],
@@ -548,7 +579,7 @@ var Tokenizer = /*#__PURE__*/function () {
548
579
  } // Get next list item
549
580
 
550
581
 
551
- var itemRegex = new RegExp("^( {0,3}" + bull + ")((?: [^\\n]*)?(?:\\n|$))"); // Check if current bullet point can start a new List Item
582
+ var itemRegex = new RegExp("^( {0,3}" + bull + ")((?:[\t ][^\\n]*)?(?:\\n|$))"); // Check if current bullet point can start a new List Item
552
583
 
553
584
  while (src) {
554
585
  endEarly = false;
@@ -589,7 +620,8 @@ var Tokenizer = /*#__PURE__*/function () {
589
620
  }
590
621
 
591
622
  if (!endEarly) {
592
- var nextBulletRegex = new RegExp("^ {0," + Math.min(3, indent - 1) + "}(?:[*+-]|\\d{1,9}[.)])"); // Check if following lines should be included in List Item
623
+ var nextBulletRegex = new RegExp("^ {0," + Math.min(3, indent - 1) + "}(?:[*+-]|\\d{1,9}[.)])((?: [^\\n]*)?(?:\\n|$))");
624
+ var hrRegex = new RegExp("^ {0," + Math.min(3, indent - 1) + "}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)"); // Check if following lines should be included in List Item
593
625
 
594
626
  while (src) {
595
627
  rawLine = src.split('\n', 1)[0];
@@ -602,6 +634,11 @@ var Tokenizer = /*#__PURE__*/function () {
602
634
 
603
635
  if (nextBulletRegex.test(line)) {
604
636
  break;
637
+ } // Horizontal rule found
638
+
639
+
640
+ if (hrRegex.test(src)) {
641
+ break;
605
642
  }
606
643
 
607
644
  if (line.search(/[^ ]/) >= indent || !line.trim()) {
@@ -1185,10 +1222,10 @@ var block = {
1185
1222
  newline: /^(?: *(?:\n|$))+/,
1186
1223
  code: /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,
1187
1224
  fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?=\n|$)|$)/,
1188
- hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
1225
+ hr: /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,
1189
1226
  heading: /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,
1190
1227
  blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
1191
- list: /^( {0,3}bull)( [^\n]+?)?(?:\n|$)/,
1228
+ list: /^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,
1192
1229
  html: '^ {0,3}(?:' // optional indentation
1193
1230
  + '<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
1194
1231
  + '|comment[^\\n]*(\\n+|$)' // (2)
@@ -1278,9 +1315,9 @@ var inline = {
1278
1315
  emStrong: {
1279
1316
  lDelim: /^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,
1280
1317
  // (1) and (2) can only be a Right Delimiter. (3) and (4) can only be Left. (5) and (6) can be either Left or Right.
1281
- // () Skip orphan delim inside strong (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a
1282
- rDelimAst: /^[^_*]*?\_\_[^_*]*?\*[^_*]*?(?=\_\_)|[punct_](\*+)(?=[\s]|$)|[^punct*_\s](\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|[^punct*_\s](\*+)(?=[^punct*_\s])/,
1283
- rDelimUnd: /^[^_*]*?\*\*[^_*]*?\_[^_*]*?(?=\*\*)|[punct*](\_+)(?=[\s]|$)|[^punct*_\s](\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/ // ^- Not allowed for _
1318
+ // () Skip orphan inside strong () Consume to delim (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a
1319
+ rDelimAst: /^[^_*]*?\_\_[^_*]*?\*[^_*]*?(?=\_\_)|[^*]+(?=[^*])|[punct_](\*+)(?=[\s]|$)|[^punct*_\s](\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|[^punct*_\s](\*+)(?=[^punct*_\s])/,
1320
+ rDelimUnd: /^[^_*]*?\*\*[^_*]*?\_[^_*]*?(?=\*\*)|[^_]+(?=[^_])|[punct*](\_+)(?=[\s]|$)|[^punct*_\s](\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/ // ^- Not allowed for _
1284
1321
 
1285
1322
  },
1286
1323
  code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
@@ -1362,6 +1399,7 @@ inline.breaks = merge({}, inline.gfm, {
1362
1399
 
1363
1400
  /**
1364
1401
  * smartypants text replacement
1402
+ * @param {string} text
1365
1403
  */
1366
1404
 
1367
1405
  function smartypants(text) {
@@ -1376,6 +1414,7 @@ function smartypants(text) {
1376
1414
  }
1377
1415
  /**
1378
1416
  * mangle email addresses
1417
+ * @param {string} text
1379
1418
  */
1380
1419
 
1381
1420
 
@@ -1466,7 +1505,7 @@ var Lexer = /*#__PURE__*/function () {
1466
1505
  var _proto = Lexer.prototype;
1467
1506
 
1468
1507
  _proto.lex = function lex(src) {
1469
- src = src.replace(/\r\n|\r/g, '\n').replace(/\t/g, ' ');
1508
+ src = src.replace(/\r\n|\r/g, '\n');
1470
1509
  this.blockTokens(src, this.tokens);
1471
1510
  var next;
1472
1511
 
@@ -1489,7 +1528,11 @@ var Lexer = /*#__PURE__*/function () {
1489
1528
  }
1490
1529
 
1491
1530
  if (this.options.pedantic) {
1492
- src = src.replace(/^ +$/gm, '');
1531
+ src = src.replace(/\t/g, ' ').replace(/^ +$/gm, '');
1532
+ } else {
1533
+ src = src.replace(/^( *)(\t+)/gm, function (_, leading, tabs) {
1534
+ return leading + ' '.repeat(tabs.length);
1535
+ });
1493
1536
  }
1494
1537
 
1495
1538
  var token, lastToken, cutSrc, lastParagraphClipped;
@@ -1949,23 +1992,35 @@ var Renderer = /*#__PURE__*/function () {
1949
1992
  }
1950
1993
 
1951
1994
  return '<pre><code class="' + this.options.langPrefix + escape(lang, true) + '">' + (escaped ? _code : escape(_code, true)) + '</code></pre>\n';
1952
- };
1995
+ }
1996
+ /**
1997
+ * @param {string} quote
1998
+ */
1999
+ ;
1953
2000
 
1954
2001
  _proto.blockquote = function blockquote(quote) {
1955
- return '<blockquote>\n' + quote + '</blockquote>\n';
2002
+ return "<blockquote>\n" + quote + "</blockquote>\n";
1956
2003
  };
1957
2004
 
1958
2005
  _proto.html = function html(_html) {
1959
2006
  return _html;
1960
- };
2007
+ }
2008
+ /**
2009
+ * @param {string} text
2010
+ * @param {string} level
2011
+ * @param {string} raw
2012
+ * @param {any} slugger
2013
+ */
2014
+ ;
1961
2015
 
1962
2016
  _proto.heading = function heading(text, level, raw, slugger) {
1963
2017
  if (this.options.headerIds) {
1964
- return '<h' + level + ' id="' + this.options.headerPrefix + slugger.slug(raw) + '">' + text + '</h' + level + '>\n';
2018
+ var id = this.options.headerPrefix + slugger.slug(raw);
2019
+ return "<h" + level + " id=\"" + id + "\">" + text + "</h" + level + ">\n";
1965
2020
  } // ignore IDs
1966
2021
 
1967
2022
 
1968
- return '<h' + level + '>' + text + '</h' + level + '>\n';
2023
+ return "<h" + level + ">" + text + "</h" + level + ">\n";
1969
2024
  };
1970
2025
 
1971
2026
  _proto.hr = function hr() {
@@ -1976,55 +2031,94 @@ var Renderer = /*#__PURE__*/function () {
1976
2031
  var type = ordered ? 'ol' : 'ul',
1977
2032
  startatt = ordered && start !== 1 ? ' start="' + start + '"' : '';
1978
2033
  return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
1979
- };
2034
+ }
2035
+ /**
2036
+ * @param {string} text
2037
+ */
2038
+ ;
1980
2039
 
1981
2040
  _proto.listitem = function listitem(text) {
1982
- return '<li>' + text + '</li>\n';
2041
+ return "<li>" + text + "</li>\n";
1983
2042
  };
1984
2043
 
1985
2044
  _proto.checkbox = function checkbox(checked) {
1986
2045
  return '<input ' + (checked ? 'checked="" ' : '') + 'disabled="" type="checkbox"' + (this.options.xhtml ? ' /' : '') + '> ';
1987
- };
2046
+ }
2047
+ /**
2048
+ * @param {string} text
2049
+ */
2050
+ ;
1988
2051
 
1989
2052
  _proto.paragraph = function paragraph(text) {
1990
- return '<p>' + text + '</p>\n';
1991
- };
2053
+ return "<p>" + text + "</p>\n";
2054
+ }
2055
+ /**
2056
+ * @param {string} header
2057
+ * @param {string} body
2058
+ */
2059
+ ;
1992
2060
 
1993
2061
  _proto.table = function table(header, body) {
1994
- if (body) body = '<tbody>' + body + '</tbody>';
2062
+ if (body) body = "<tbody>" + body + "</tbody>";
1995
2063
  return '<table>\n' + '<thead>\n' + header + '</thead>\n' + body + '</table>\n';
1996
- };
2064
+ }
2065
+ /**
2066
+ * @param {string} content
2067
+ */
2068
+ ;
1997
2069
 
1998
2070
  _proto.tablerow = function tablerow(content) {
1999
- return '<tr>\n' + content + '</tr>\n';
2071
+ return "<tr>\n" + content + "</tr>\n";
2000
2072
  };
2001
2073
 
2002
2074
  _proto.tablecell = function tablecell(content, flags) {
2003
2075
  var type = flags.header ? 'th' : 'td';
2004
- var tag = flags.align ? '<' + type + ' align="' + flags.align + '">' : '<' + type + '>';
2005
- return tag + content + '</' + type + '>\n';
2006
- } // span level renderer
2076
+ var tag = flags.align ? "<" + type + " align=\"" + flags.align + "\">" : "<" + type + ">";
2077
+ return tag + content + ("</" + type + ">\n");
2078
+ }
2079
+ /**
2080
+ * span level renderer
2081
+ * @param {string} text
2082
+ */
2007
2083
  ;
2008
2084
 
2009
2085
  _proto.strong = function strong(text) {
2010
- return '<strong>' + text + '</strong>';
2011
- };
2086
+ return "<strong>" + text + "</strong>";
2087
+ }
2088
+ /**
2089
+ * @param {string} text
2090
+ */
2091
+ ;
2012
2092
 
2013
2093
  _proto.em = function em(text) {
2014
- return '<em>' + text + '</em>';
2015
- };
2094
+ return "<em>" + text + "</em>";
2095
+ }
2096
+ /**
2097
+ * @param {string} text
2098
+ */
2099
+ ;
2016
2100
 
2017
2101
  _proto.codespan = function codespan(text) {
2018
- return '<code>' + text + '</code>';
2102
+ return "<code>" + text + "</code>";
2019
2103
  };
2020
2104
 
2021
2105
  _proto.br = function br() {
2022
2106
  return this.options.xhtml ? '<br/>' : '<br>';
2023
- };
2107
+ }
2108
+ /**
2109
+ * @param {string} text
2110
+ */
2111
+ ;
2024
2112
 
2025
2113
  _proto.del = function del(text) {
2026
- return '<del>' + text + '</del>';
2027
- };
2114
+ return "<del>" + text + "</del>";
2115
+ }
2116
+ /**
2117
+ * @param {string} href
2118
+ * @param {string} title
2119
+ * @param {string} text
2120
+ */
2121
+ ;
2028
2122
 
2029
2123
  _proto.link = function link(href, title, text) {
2030
2124
  href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
@@ -2041,7 +2135,13 @@ var Renderer = /*#__PURE__*/function () {
2041
2135
 
2042
2136
  out += '>' + text + '</a>';
2043
2137
  return out;
2044
- };
2138
+ }
2139
+ /**
2140
+ * @param {string} href
2141
+ * @param {string} title
2142
+ * @param {string} text
2143
+ */
2144
+ ;
2045
2145
 
2046
2146
  _proto.image = function image(href, title, text) {
2047
2147
  href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
@@ -2050,10 +2150,10 @@ var Renderer = /*#__PURE__*/function () {
2050
2150
  return text;
2051
2151
  }
2052
2152
 
2053
- var out = '<img src="' + href + '" alt="' + text + '"';
2153
+ var out = "<img src=\"" + href + "\" alt=\"" + text + "\"";
2054
2154
 
2055
2155
  if (title) {
2056
- out += ' title="' + title + '"';
2156
+ out += " title=\"" + title + "\"";
2057
2157
  }
2058
2158
 
2059
2159
  out += this.options.xhtml ? '/>' : '>';
@@ -2123,6 +2223,10 @@ var Slugger = /*#__PURE__*/function () {
2123
2223
  function Slugger() {
2124
2224
  this.seen = {};
2125
2225
  }
2226
+ /**
2227
+ * @param {string} value
2228
+ */
2229
+
2126
2230
 
2127
2231
  var _proto = Slugger.prototype;
2128
2232
 
@@ -2133,6 +2237,8 @@ var Slugger = /*#__PURE__*/function () {
2133
2237
  }
2134
2238
  /**
2135
2239
  * Finds the next safe (unique) slug to use
2240
+ * @param {string} originalSlug
2241
+ * @param {boolean} isDryRun
2136
2242
  */
2137
2243
  ;
2138
2244
 
@@ -2158,8 +2264,9 @@ var Slugger = /*#__PURE__*/function () {
2158
2264
  }
2159
2265
  /**
2160
2266
  * Convert string to unique id
2161
- * @param {object} options
2162
- * @param {boolean} options.dryrun Generates the next unique slug without updating the internal accumulator.
2267
+ * @param {object} [options]
2268
+ * @param {boolean} [options.dryrun] Generates the next unique slug without
2269
+ * updating the internal accumulator.
2163
2270
  */
2164
2271
  ;
2165
2272
 
@@ -2856,6 +2963,7 @@ marked.walkTokens = function (tokens, callback) {
2856
2963
  };
2857
2964
  /**
2858
2965
  * Parse Inline
2966
+ * @param {string} src
2859
2967
  */
2860
2968
 
2861
2969