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