marked 14.0.0 → 14.1.1
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.cjs +43 -27
- package/lib/marked.cjs.map +1 -1
- package/lib/marked.d.cts +12 -49
- package/lib/marked.d.ts +12 -49
- package/lib/marked.esm.js +43 -27
- package/lib/marked.esm.js.map +1 -1
- package/lib/marked.umd.js +43 -27
- package/lib/marked.umd.js.map +1 -1
- package/man/marked.1 +1 -1
- package/marked.min.js +2 -2
- package/package.json +12 -12
package/lib/marked.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* marked v14.
|
|
2
|
+
* marked v14.1.1 - a markdown parser
|
|
3
3
|
* Copyright (c) 2011-2024, Christopher Jeffrey. (MIT Licensed)
|
|
4
4
|
* https://github.com/markedjs/marked
|
|
5
5
|
*/
|
|
@@ -249,7 +249,7 @@ class _Tokenizer {
|
|
|
249
249
|
code(src) {
|
|
250
250
|
const cap = this.rules.block.code.exec(src);
|
|
251
251
|
if (cap) {
|
|
252
|
-
const text = cap[0].replace(/^ {1,4}/gm, '');
|
|
252
|
+
const text = cap[0].replace(/^(?: {1,4}| {0,3}\t)/gm, '');
|
|
253
253
|
return {
|
|
254
254
|
type: 'code',
|
|
255
255
|
raw: cap[0],
|
|
@@ -433,7 +433,7 @@ class _Tokenizer {
|
|
|
433
433
|
itemContents = line.slice(indent);
|
|
434
434
|
indent += cap[1].length;
|
|
435
435
|
}
|
|
436
|
-
if (blankLine && /^ *$/.test(nextLine)) { // Items begin with at most one blank line
|
|
436
|
+
if (blankLine && /^[ \t]*$/.test(nextLine)) { // Items begin with at most one blank line
|
|
437
437
|
raw += nextLine + '\n';
|
|
438
438
|
src = src.substring(nextLine.length + 1);
|
|
439
439
|
endEarly = true;
|
|
@@ -446,10 +446,15 @@ class _Tokenizer {
|
|
|
446
446
|
// Check if following lines should be included in List Item
|
|
447
447
|
while (src) {
|
|
448
448
|
const rawLine = src.split('\n', 1)[0];
|
|
449
|
+
let nextLineWithoutTabs;
|
|
449
450
|
nextLine = rawLine;
|
|
450
451
|
// Re-align to follow commonmark nesting rules
|
|
451
452
|
if (this.options.pedantic) {
|
|
452
453
|
nextLine = nextLine.replace(/^ {1,4}(?=( {4})*[^ ])/g, ' ');
|
|
454
|
+
nextLineWithoutTabs = nextLine;
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
nextLineWithoutTabs = nextLine.replace(/\t/g, ' ');
|
|
453
458
|
}
|
|
454
459
|
// End list item if found code fences
|
|
455
460
|
if (fencesBeginRegex.test(nextLine)) {
|
|
@@ -464,11 +469,11 @@ class _Tokenizer {
|
|
|
464
469
|
break;
|
|
465
470
|
}
|
|
466
471
|
// Horizontal rule found
|
|
467
|
-
if (hrRegex.test(
|
|
472
|
+
if (hrRegex.test(nextLine)) {
|
|
468
473
|
break;
|
|
469
474
|
}
|
|
470
|
-
if (
|
|
471
|
-
itemContents += '\n' +
|
|
475
|
+
if (nextLineWithoutTabs.search(/[^ ]/) >= indent || !nextLine.trim()) { // Dedent if possible
|
|
476
|
+
itemContents += '\n' + nextLineWithoutTabs.slice(indent);
|
|
472
477
|
}
|
|
473
478
|
else {
|
|
474
479
|
// not enough indentation
|
|
@@ -476,7 +481,7 @@ class _Tokenizer {
|
|
|
476
481
|
break;
|
|
477
482
|
}
|
|
478
483
|
// paragraph continuation unless last line was a different block level element
|
|
479
|
-
if (line.search(/[^ ]/) >= 4) { // indented code block
|
|
484
|
+
if (line.replace(/\t/g, ' ').search(/[^ ]/) >= 4) { // indented code block
|
|
480
485
|
break;
|
|
481
486
|
}
|
|
482
487
|
if (fencesBeginRegex.test(line)) {
|
|
@@ -495,7 +500,7 @@ class _Tokenizer {
|
|
|
495
500
|
}
|
|
496
501
|
raw += rawLine + '\n';
|
|
497
502
|
src = src.substring(rawLine.length + 1);
|
|
498
|
-
line =
|
|
503
|
+
line = nextLineWithoutTabs.slice(indent);
|
|
499
504
|
}
|
|
500
505
|
}
|
|
501
506
|
if (!list.loose) {
|
|
@@ -503,7 +508,7 @@ class _Tokenizer {
|
|
|
503
508
|
if (endsWithBlankLine) {
|
|
504
509
|
list.loose = true;
|
|
505
510
|
}
|
|
506
|
-
else if (/\n *\n *$/.test(raw)) {
|
|
511
|
+
else if (/\n[ \t]*\n[ \t]*$/.test(raw)) {
|
|
507
512
|
endsWithBlankLine = true;
|
|
508
513
|
}
|
|
509
514
|
}
|
|
@@ -965,15 +970,15 @@ class _Tokenizer {
|
|
|
965
970
|
/**
|
|
966
971
|
* Block-Level Grammar
|
|
967
972
|
*/
|
|
968
|
-
const newline = /^(?: *(?:\n|$))+/;
|
|
969
|
-
const blockCode = /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/;
|
|
973
|
+
const newline = /^(?:[ \t]*(?:\n|$))+/;
|
|
974
|
+
const blockCode = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/;
|
|
970
975
|
const fences = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/;
|
|
971
976
|
const hr = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
|
|
972
977
|
const heading = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/;
|
|
973
978
|
const bullet = /(?:[*+-]|\d{1,9}[.)])/;
|
|
974
979
|
const lheading = edit(/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/)
|
|
975
980
|
.replace(/bull/g, bullet) // lists can interrupt
|
|
976
|
-
.replace(/blockCode/g, / {4}/) // indented code blocks can interrupt
|
|
981
|
+
.replace(/blockCode/g, /(?: {4}| {0,3}\t)/) // indented code blocks can interrupt
|
|
977
982
|
.replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/) // fenced code blocks can interrupt
|
|
978
983
|
.replace(/blockquote/g, / {0,3}>/) // blockquote can interrupt
|
|
979
984
|
.replace(/heading/g, / {0,3}#{1,6}/) // ATX heading can interrupt
|
|
@@ -982,7 +987,7 @@ const lheading = edit(/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|
|
|
|
982
987
|
const _paragraph = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/;
|
|
983
988
|
const blockText = /^[^\n]+/;
|
|
984
989
|
const _blockLabel = /(?!\s*\])(?:\\.|[^\[\]\\])+/;
|
|
985
|
-
const def = edit(/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/)
|
|
990
|
+
const def = edit(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/)
|
|
986
991
|
.replace('label', _blockLabel)
|
|
987
992
|
.replace('title', /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/)
|
|
988
993
|
.getRegex();
|
|
@@ -1002,9 +1007,9 @@ const html = edit('^ {0,3}(?:' // optional indentation
|
|
|
1002
1007
|
+ '|<\\?[\\s\\S]*?(?:\\?>\\n*|$)' // (3)
|
|
1003
1008
|
+ '|<![A-Z][\\s\\S]*?(?:>\\n*|$)' // (4)
|
|
1004
1009
|
+ '|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)' // (5)
|
|
1005
|
-
+ '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (6)
|
|
1006
|
-
+ '|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) open tag
|
|
1007
|
-
+ '|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) closing tag
|
|
1010
|
+
+ '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)' // (6)
|
|
1011
|
+
+ '|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)' // (7) open tag
|
|
1012
|
+
+ '|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)' // (7) closing tag
|
|
1008
1013
|
+ ')', 'i')
|
|
1009
1014
|
.replace('comment', _comment)
|
|
1010
1015
|
.replace('tag', _tag)
|
|
@@ -1051,7 +1056,7 @@ const gfmTable = edit('^ *([^\\n ].*)\\n' // Header
|
|
|
1051
1056
|
.replace('hr', hr)
|
|
1052
1057
|
.replace('heading', ' {0,3}#{1,6}(?:\\s|$)')
|
|
1053
1058
|
.replace('blockquote', ' {0,3}>')
|
|
1054
|
-
.replace('code', ' {4}[^\\n]')
|
|
1059
|
+
.replace('code', '(?: {4}| {0,3}\t)[^\\n]')
|
|
1055
1060
|
.replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
|
|
1056
1061
|
.replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
|
|
1057
1062
|
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)')
|
|
@@ -1331,11 +1336,6 @@ class _Lexer {
|
|
|
1331
1336
|
if (this.options.pedantic) {
|
|
1332
1337
|
src = src.replace(/\t/g, ' ').replace(/^ +$/gm, '');
|
|
1333
1338
|
}
|
|
1334
|
-
else {
|
|
1335
|
-
src = src.replace(/^( *)(\t+)/gm, (_, leading, tabs) => {
|
|
1336
|
-
return leading + ' '.repeat(tabs.length);
|
|
1337
|
-
});
|
|
1338
|
-
}
|
|
1339
1339
|
let token;
|
|
1340
1340
|
let lastToken;
|
|
1341
1341
|
let cutSrc;
|
|
@@ -2078,6 +2078,7 @@ class _Parser {
|
|
|
2078
2078
|
|
|
2079
2079
|
class _Hooks {
|
|
2080
2080
|
options;
|
|
2081
|
+
block;
|
|
2081
2082
|
constructor(options) {
|
|
2082
2083
|
this.options = options || exports.defaults;
|
|
2083
2084
|
}
|
|
@@ -2104,13 +2105,25 @@ class _Hooks {
|
|
|
2104
2105
|
processAllTokens(tokens) {
|
|
2105
2106
|
return tokens;
|
|
2106
2107
|
}
|
|
2108
|
+
/**
|
|
2109
|
+
* Provide function to tokenize markdown
|
|
2110
|
+
*/
|
|
2111
|
+
provideLexer() {
|
|
2112
|
+
return this.block ? _Lexer.lex : _Lexer.lexInline;
|
|
2113
|
+
}
|
|
2114
|
+
/**
|
|
2115
|
+
* Provide function to parse tokens
|
|
2116
|
+
*/
|
|
2117
|
+
provideParser() {
|
|
2118
|
+
return this.block ? _Parser.parse : _Parser.parseInline;
|
|
2119
|
+
}
|
|
2107
2120
|
}
|
|
2108
2121
|
|
|
2109
2122
|
class Marked {
|
|
2110
2123
|
defaults = _getDefaults();
|
|
2111
2124
|
options = this.setOptions;
|
|
2112
|
-
parse = this.parseMarkdown(
|
|
2113
|
-
parseInline = this.parseMarkdown(
|
|
2125
|
+
parse = this.parseMarkdown(true);
|
|
2126
|
+
parseInline = this.parseMarkdown(false);
|
|
2114
2127
|
Parser = _Parser;
|
|
2115
2128
|
Renderer = _Renderer;
|
|
2116
2129
|
TextRenderer = _TextRenderer;
|
|
@@ -2283,8 +2296,8 @@ class Marked {
|
|
|
2283
2296
|
if (!(prop in hooks)) {
|
|
2284
2297
|
throw new Error(`hook '${prop}' does not exist`);
|
|
2285
2298
|
}
|
|
2286
|
-
if (
|
|
2287
|
-
// ignore options
|
|
2299
|
+
if (['options', 'block'].includes(prop)) {
|
|
2300
|
+
// ignore options and block properties
|
|
2288
2301
|
continue;
|
|
2289
2302
|
}
|
|
2290
2303
|
const hooksProp = prop;
|
|
@@ -2342,7 +2355,7 @@ class Marked {
|
|
|
2342
2355
|
parser(tokens, options) {
|
|
2343
2356
|
return _Parser.parse(tokens, options ?? this.defaults);
|
|
2344
2357
|
}
|
|
2345
|
-
parseMarkdown(
|
|
2358
|
+
parseMarkdown(blockType) {
|
|
2346
2359
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2347
2360
|
const parse = (src, options) => {
|
|
2348
2361
|
const origOpt = { ...options };
|
|
@@ -2362,7 +2375,10 @@ class Marked {
|
|
|
2362
2375
|
}
|
|
2363
2376
|
if (opt.hooks) {
|
|
2364
2377
|
opt.hooks.options = opt;
|
|
2378
|
+
opt.hooks.block = blockType;
|
|
2365
2379
|
}
|
|
2380
|
+
const lexer = opt.hooks ? opt.hooks.provideLexer() : (blockType ? _Lexer.lex : _Lexer.lexInline);
|
|
2381
|
+
const parser = opt.hooks ? opt.hooks.provideParser() : (blockType ? _Parser.parse : _Parser.parseInline);
|
|
2366
2382
|
if (opt.async) {
|
|
2367
2383
|
return Promise.resolve(opt.hooks ? opt.hooks.preprocess(src) : src)
|
|
2368
2384
|
.then(src => lexer(src, opt))
|