marked 7.0.1 → 7.0.3
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 +38 -27
- package/lib/marked.cjs.map +1 -1
- package/lib/marked.d.ts +111 -110
- package/lib/marked.esm.js +38 -27
- package/lib/marked.esm.js.map +1 -1
- package/lib/marked.umd.js +38 -27
- package/lib/marked.umd.js.map +1 -1
- package/marked.min.js +3 -3
- package/package.json +7 -7
- package/src/Hooks.ts +0 -29
- package/src/Instance.ts +0 -381
- package/src/Lexer.ts +0 -517
- package/src/MarkedOptions.ts +0 -212
- package/src/Parser.ts +0 -291
- package/src/Renderer.ts +0 -167
- package/src/Slugger.ts +0 -51
- package/src/TextRenderer.ts +0 -42
- package/src/Tokenizer.ts +0 -810
- package/src/Tokens.ts +0 -199
- package/src/defaults.ts +0 -35
- package/src/helpers.ts +0 -264
- package/src/marked.ts +0 -143
- package/src/rules.ts +0 -380
package/lib/marked.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare module "Tokens" {
|
|
2
|
-
export type Token = (Tokens.Space | Tokens.Code | Tokens.Heading | Tokens.Table | Tokens.Hr | Tokens.Blockquote | Tokens.List | Tokens.ListItem | Tokens.Paragraph | Tokens.HTML | Tokens.Text | Tokens.Def | Tokens.Escape | Tokens.Tag | Tokens.Image | Tokens.Link | Tokens.Strong | Tokens.Em | Tokens.Codespan | Tokens.Br | Tokens.Del) & {
|
|
2
|
+
export type Token = (Tokens.Space | Tokens.Code | Tokens.Heading | Tokens.Table | Tokens.Hr | Tokens.Blockquote | Tokens.List | Tokens.ListItem | Tokens.Paragraph | Tokens.HTML | Tokens.Text | Tokens.Def | Tokens.Escape | Tokens.Tag | Tokens.Image | Tokens.Link | Tokens.Strong | Tokens.Em | Tokens.Codespan | Tokens.Br | Tokens.Del | Tokens.Generic) & {
|
|
3
3
|
loose?: boolean;
|
|
4
4
|
tokens?: Token[];
|
|
5
5
|
};
|
|
@@ -25,7 +25,7 @@ declare module "Tokens" {
|
|
|
25
25
|
}
|
|
26
26
|
interface Table {
|
|
27
27
|
type: 'table';
|
|
28
|
-
raw
|
|
28
|
+
raw: string;
|
|
29
29
|
align: Array<'center' | 'left' | 'right' | null>;
|
|
30
30
|
header: TableCell[];
|
|
31
31
|
rows: TableCell[][];
|
|
@@ -156,7 +156,7 @@ declare module "Tokens" {
|
|
|
156
156
|
};
|
|
157
157
|
}
|
|
158
158
|
declare module "Tokenizer" {
|
|
159
|
-
import { _Lexer } from "Lexer";
|
|
159
|
+
import type { _Lexer } from "Lexer";
|
|
160
160
|
import type { Links, Tokens } from "Tokens";
|
|
161
161
|
import type { MarkedOptions } from "MarkedOptions";
|
|
162
162
|
/**
|
|
@@ -309,7 +309,7 @@ declare module "Instance" {
|
|
|
309
309
|
export class Marked {
|
|
310
310
|
#private;
|
|
311
311
|
defaults: MarkedOptions;
|
|
312
|
-
options: (opt:
|
|
312
|
+
options: (opt: MarkedOptions) => this;
|
|
313
313
|
parse: (src: string, optOrCallback?: MarkedOptions | ResultCallback | undefined | null, callback?: ResultCallback | undefined) => string | Promise<string | undefined> | undefined;
|
|
314
314
|
parseInline: (src: string, optOrCallback?: MarkedOptions | ResultCallback | undefined | null, callback?: ResultCallback | undefined) => string | Promise<string | undefined> | undefined;
|
|
315
315
|
Parser: typeof _Parser;
|
|
@@ -327,7 +327,7 @@ declare module "Instance" {
|
|
|
327
327
|
*/
|
|
328
328
|
walkTokens<T = void>(tokens: Token[] | TokensList, callback: (token: Token) => T | T[]): T[];
|
|
329
329
|
use(...args: MarkedExtension[]): this;
|
|
330
|
-
setOptions(opt:
|
|
330
|
+
setOptions(opt: MarkedOptions): this;
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
333
|
declare module "helpers" {
|
|
@@ -345,7 +345,7 @@ declare module "helpers" {
|
|
|
345
345
|
export const noopTest: {
|
|
346
346
|
exec: () => null;
|
|
347
347
|
};
|
|
348
|
-
export function splitCells(tableRow: string, count
|
|
348
|
+
export function splitCells(tableRow: string, count?: number): string[];
|
|
349
349
|
/**
|
|
350
350
|
* Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
|
|
351
351
|
* /c*$/ is vulnerable to REDOS.
|
|
@@ -358,101 +358,9 @@ declare module "helpers" {
|
|
|
358
358
|
export function findClosingBracket(str: string, b: string): number;
|
|
359
359
|
export function checkDeprecations(opt: MarkedOptions, callback?: ResultCallback): void;
|
|
360
360
|
}
|
|
361
|
-
declare module "marked" {
|
|
362
|
-
import { _Lexer } from "Lexer";
|
|
363
|
-
import { _Parser } from "Parser";
|
|
364
|
-
import { _Tokenizer } from "Tokenizer";
|
|
365
|
-
import { _Renderer } from "Renderer";
|
|
366
|
-
import { _TextRenderer } from "TextRenderer";
|
|
367
|
-
import { _Slugger } from "Slugger";
|
|
368
|
-
import { _Hooks } from "Hooks";
|
|
369
|
-
import { _getDefaults } from "defaults";
|
|
370
|
-
import type { MarkedExtension, MarkedOptions } from "MarkedOptions";
|
|
371
|
-
import type { Token, TokensList } from "Tokens";
|
|
372
|
-
import type { ResultCallback } from "Instance";
|
|
373
|
-
/**
|
|
374
|
-
* Compiles markdown to HTML asynchronously.
|
|
375
|
-
*
|
|
376
|
-
* @param src String of markdown source to be compiled
|
|
377
|
-
* @param options Hash of options, having async: true
|
|
378
|
-
* @return Promise of string of compiled HTML
|
|
379
|
-
*/
|
|
380
|
-
export function marked(src: string, options: MarkedOptions & {
|
|
381
|
-
async: true;
|
|
382
|
-
}): Promise<string>;
|
|
383
|
-
/**
|
|
384
|
-
* Compiles markdown to HTML synchronously.
|
|
385
|
-
*
|
|
386
|
-
* @param src String of markdown source to be compiled
|
|
387
|
-
* @param options Optional hash of options
|
|
388
|
-
* @return String of compiled HTML
|
|
389
|
-
*/
|
|
390
|
-
export function marked(src: string, options?: MarkedOptions): string;
|
|
391
|
-
/**
|
|
392
|
-
* Compiles markdown to HTML asynchronously with a callback.
|
|
393
|
-
*
|
|
394
|
-
* @param src String of markdown source to be compiled
|
|
395
|
-
* @param callback Function called when the markdownString has been fully parsed when using async highlighting
|
|
396
|
-
*/
|
|
397
|
-
export function marked(src: string, callback: ResultCallback): void;
|
|
398
|
-
/**
|
|
399
|
-
* Compiles markdown to HTML asynchronously with a callback.
|
|
400
|
-
*
|
|
401
|
-
* @param src String of markdown source to be compiled
|
|
402
|
-
* @param options Hash of options
|
|
403
|
-
* @param callback Function called when the markdownString has been fully parsed when using async highlighting
|
|
404
|
-
*/
|
|
405
|
-
export function marked(src: string, options: MarkedOptions, callback: ResultCallback): void;
|
|
406
|
-
/**
|
|
407
|
-
* Compiles markdown to HTML asynchronously with a callback.
|
|
408
|
-
*
|
|
409
|
-
* @param src String of markdown source to be compiled
|
|
410
|
-
* @param options Hash of options
|
|
411
|
-
* @param callback Function called when the markdownString has been fully parsed when using async highlighting
|
|
412
|
-
*/
|
|
413
|
-
export namespace marked {
|
|
414
|
-
var options: (options: MarkedOptions) => typeof marked;
|
|
415
|
-
var setOptions: (options: MarkedOptions) => typeof marked;
|
|
416
|
-
var getDefaults: typeof _getDefaults;
|
|
417
|
-
var defaults: MarkedOptions;
|
|
418
|
-
var use: (...args: MarkedExtension[]) => typeof marked;
|
|
419
|
-
var walkTokens: <T = void>(tokens: Token[] | TokensList, callback: (token: Token) => T | T[]) => T[];
|
|
420
|
-
var parseInline: (src: string, optOrCallback?: MarkedOptions | ResultCallback | null | undefined, callback?: ResultCallback | undefined) => string | Promise<string | undefined> | undefined;
|
|
421
|
-
var Parser: typeof _Parser;
|
|
422
|
-
var parser: typeof _Parser.parse;
|
|
423
|
-
var Renderer: typeof _Renderer;
|
|
424
|
-
var TextRenderer: typeof _TextRenderer;
|
|
425
|
-
var Lexer: typeof _Lexer;
|
|
426
|
-
var lexer: typeof _Lexer.lex;
|
|
427
|
-
var Tokenizer: typeof _Tokenizer;
|
|
428
|
-
var Slugger: typeof _Slugger;
|
|
429
|
-
var Hooks: typeof _Hooks;
|
|
430
|
-
var parse: typeof marked;
|
|
431
|
-
}
|
|
432
|
-
export const options: (options: MarkedOptions) => typeof marked;
|
|
433
|
-
export const setOptions: (options: MarkedOptions) => typeof marked;
|
|
434
|
-
export const use: (...args: MarkedExtension[]) => typeof marked;
|
|
435
|
-
export const walkTokens: <T = void>(tokens: Token[] | TokensList, callback: (token: Token) => T | T[]) => T[];
|
|
436
|
-
export const parseInline: (src: string, optOrCallback?: MarkedOptions | ResultCallback | null | undefined, callback?: ResultCallback | undefined) => string | Promise<string | undefined> | undefined;
|
|
437
|
-
export const parse: typeof marked;
|
|
438
|
-
export const parser: typeof _Parser.parse;
|
|
439
|
-
export const lexer: typeof _Lexer.lex;
|
|
440
|
-
export { _defaults as defaults, _getDefaults as getDefaults } from "defaults";
|
|
441
|
-
export { _Lexer as Lexer } from "Lexer";
|
|
442
|
-
export { _Parser as Parser } from "Parser";
|
|
443
|
-
export { _Tokenizer as Tokenizer } from "Tokenizer";
|
|
444
|
-
export { _Renderer as Renderer } from "Renderer";
|
|
445
|
-
export { _TextRenderer as TextRenderer } from "TextRenderer";
|
|
446
|
-
export { _Slugger as Slugger } from "Slugger";
|
|
447
|
-
export { _Hooks as Hooks } from "Hooks";
|
|
448
|
-
export { Marked } from "Instance";
|
|
449
|
-
export type * from "MarkedOptions";
|
|
450
|
-
export type * from "rules";
|
|
451
|
-
export type * from "Tokens";
|
|
452
|
-
}
|
|
453
361
|
declare module "Renderer" {
|
|
454
362
|
import type { MarkedOptions } from "MarkedOptions";
|
|
455
|
-
import {
|
|
363
|
+
import type { _Slugger } from "Slugger";
|
|
456
364
|
/**
|
|
457
365
|
* Renderer
|
|
458
366
|
*/
|
|
@@ -462,7 +370,7 @@ declare module "Renderer" {
|
|
|
462
370
|
code(code: string, infostring: string | undefined, escaped: boolean): string;
|
|
463
371
|
blockquote(quote: string): string;
|
|
464
372
|
html(html: string, block?: boolean): string;
|
|
465
|
-
heading(text: string, level: number, raw: string, slugger:
|
|
373
|
+
heading(text: string, level: number, raw: string, slugger: _Slugger): string;
|
|
466
374
|
hr(): string;
|
|
467
375
|
list(body: string, ordered: boolean, start: number | ''): string;
|
|
468
376
|
listitem(text: string, task: boolean, checked: boolean): string;
|
|
@@ -522,10 +430,10 @@ declare module "Parser" {
|
|
|
522
430
|
}
|
|
523
431
|
declare module "MarkedOptions" {
|
|
524
432
|
import type { Token, Tokens, TokensList } from "Tokens";
|
|
525
|
-
import { _Parser } from "Parser";
|
|
526
|
-
import { _Lexer } from "Lexer";
|
|
527
|
-
import { _Renderer } from "Renderer";
|
|
528
|
-
import { _Tokenizer } from "Tokenizer";
|
|
433
|
+
import type { _Parser } from "Parser";
|
|
434
|
+
import type { _Lexer } from "Lexer";
|
|
435
|
+
import type { _Renderer } from "Renderer";
|
|
436
|
+
import type { _Tokenizer } from "Tokenizer";
|
|
529
437
|
export interface SluggerOptions {
|
|
530
438
|
/** Generates the next unique slug without updating the internal accumulator. */
|
|
531
439
|
dryrun?: boolean;
|
|
@@ -537,15 +445,16 @@ declare module "MarkedOptions" {
|
|
|
537
445
|
name: string;
|
|
538
446
|
level: 'block' | 'inline';
|
|
539
447
|
start?: ((this: TokenizerThis, src: string) => number | void) | undefined;
|
|
540
|
-
tokenizer: (this: TokenizerThis, src: string, tokens: Token[] | TokensList) => Tokens.Generic |
|
|
448
|
+
tokenizer: (this: TokenizerThis, src: string, tokens: Token[] | TokensList) => Tokens.Generic | undefined;
|
|
541
449
|
childTokens?: string[] | undefined;
|
|
542
450
|
}
|
|
543
451
|
export interface RendererThis {
|
|
544
452
|
parser: _Parser;
|
|
545
453
|
}
|
|
454
|
+
export type RendererExtensionFunction = (this: RendererThis, token: Tokens.Generic) => string | false | undefined;
|
|
546
455
|
export interface RendererExtension {
|
|
547
456
|
name: string;
|
|
548
|
-
renderer:
|
|
457
|
+
renderer: RendererExtensionFunction;
|
|
549
458
|
}
|
|
550
459
|
export type TokenizerAndRendererExtension = TokenizerExtension | RendererExtension | (TokenizerExtension & RendererExtension);
|
|
551
460
|
type RendererApi = Omit<_Renderer, 'constructor' | 'options'>;
|
|
@@ -602,8 +511,8 @@ declare module "MarkedOptions" {
|
|
|
602
511
|
* postprocess is called to process html after marked has finished parsing.
|
|
603
512
|
*/
|
|
604
513
|
hooks?: {
|
|
605
|
-
preprocess: (markdown: string) => string
|
|
606
|
-
postprocess: (html: string
|
|
514
|
+
preprocess: (markdown: string) => string | Promise<string>;
|
|
515
|
+
postprocess: (html: string) => string | Promise<string>;
|
|
607
516
|
options?: MarkedOptions;
|
|
608
517
|
} | null;
|
|
609
518
|
/**
|
|
@@ -688,7 +597,7 @@ declare module "MarkedOptions" {
|
|
|
688
597
|
* Add tokenizers and renderers to marked
|
|
689
598
|
*/
|
|
690
599
|
extensions?: (TokenizerAndRendererExtension[] & {
|
|
691
|
-
renderers: Record<string,
|
|
600
|
+
renderers: Record<string, RendererExtensionFunction>;
|
|
692
601
|
childTokens: Record<string, string[]>;
|
|
693
602
|
block: any[];
|
|
694
603
|
inline: any[];
|
|
@@ -719,6 +628,98 @@ declare module "Hooks" {
|
|
|
719
628
|
/**
|
|
720
629
|
* Process HTML after marked is finished
|
|
721
630
|
*/
|
|
722
|
-
postprocess(html: string
|
|
631
|
+
postprocess(html: string): string;
|
|
723
632
|
}
|
|
724
633
|
}
|
|
634
|
+
declare module "marked" {
|
|
635
|
+
import { _Lexer } from "Lexer";
|
|
636
|
+
import { _Parser } from "Parser";
|
|
637
|
+
import { _Tokenizer } from "Tokenizer";
|
|
638
|
+
import { _Renderer } from "Renderer";
|
|
639
|
+
import { _TextRenderer } from "TextRenderer";
|
|
640
|
+
import { _Slugger } from "Slugger";
|
|
641
|
+
import { _Hooks } from "Hooks";
|
|
642
|
+
import { _getDefaults } from "defaults";
|
|
643
|
+
import type { MarkedExtension, MarkedOptions } from "MarkedOptions";
|
|
644
|
+
import type { Token, TokensList } from "Tokens";
|
|
645
|
+
import type { ResultCallback } from "Instance";
|
|
646
|
+
/**
|
|
647
|
+
* Compiles markdown to HTML asynchronously.
|
|
648
|
+
*
|
|
649
|
+
* @param src String of markdown source to be compiled
|
|
650
|
+
* @param options Hash of options, having async: true
|
|
651
|
+
* @return Promise of string of compiled HTML
|
|
652
|
+
*/
|
|
653
|
+
export function marked(src: string, options: MarkedOptions & {
|
|
654
|
+
async: true;
|
|
655
|
+
}): Promise<string>;
|
|
656
|
+
/**
|
|
657
|
+
* Compiles markdown to HTML synchronously.
|
|
658
|
+
*
|
|
659
|
+
* @param src String of markdown source to be compiled
|
|
660
|
+
* @param options Optional hash of options
|
|
661
|
+
* @return String of compiled HTML
|
|
662
|
+
*/
|
|
663
|
+
export function marked(src: string, options?: MarkedOptions): string;
|
|
664
|
+
/**
|
|
665
|
+
* Compiles markdown to HTML asynchronously with a callback.
|
|
666
|
+
*
|
|
667
|
+
* @param src String of markdown source to be compiled
|
|
668
|
+
* @param callback Function called when the markdownString has been fully parsed when using async highlighting
|
|
669
|
+
*/
|
|
670
|
+
export function marked(src: string, callback: ResultCallback): void;
|
|
671
|
+
/**
|
|
672
|
+
* Compiles markdown to HTML asynchronously with a callback.
|
|
673
|
+
*
|
|
674
|
+
* @param src String of markdown source to be compiled
|
|
675
|
+
* @param options Hash of options
|
|
676
|
+
* @param callback Function called when the markdownString has been fully parsed when using async highlighting
|
|
677
|
+
*/
|
|
678
|
+
export function marked(src: string, options: MarkedOptions, callback: ResultCallback): void;
|
|
679
|
+
/**
|
|
680
|
+
* Compiles markdown to HTML asynchronously with a callback.
|
|
681
|
+
*
|
|
682
|
+
* @param src String of markdown source to be compiled
|
|
683
|
+
* @param options Hash of options
|
|
684
|
+
* @param callback Function called when the markdownString has been fully parsed when using async highlighting
|
|
685
|
+
*/
|
|
686
|
+
export namespace marked {
|
|
687
|
+
var options: (options: MarkedOptions) => typeof marked;
|
|
688
|
+
var setOptions: (options: MarkedOptions) => typeof marked;
|
|
689
|
+
var getDefaults: typeof _getDefaults;
|
|
690
|
+
var defaults: MarkedOptions;
|
|
691
|
+
var use: (...args: MarkedExtension[]) => typeof marked;
|
|
692
|
+
var walkTokens: <T = void>(tokens: Token[] | TokensList, callback: (token: Token) => T | T[]) => T[];
|
|
693
|
+
var parseInline: (src: string, optOrCallback?: MarkedOptions | ResultCallback | null | undefined, callback?: ResultCallback | undefined) => string | Promise<string | undefined> | undefined;
|
|
694
|
+
var Parser: typeof _Parser;
|
|
695
|
+
var parser: typeof _Parser.parse;
|
|
696
|
+
var Renderer: typeof _Renderer;
|
|
697
|
+
var TextRenderer: typeof _TextRenderer;
|
|
698
|
+
var Lexer: typeof _Lexer;
|
|
699
|
+
var lexer: typeof _Lexer.lex;
|
|
700
|
+
var Tokenizer: typeof _Tokenizer;
|
|
701
|
+
var Slugger: typeof _Slugger;
|
|
702
|
+
var Hooks: typeof _Hooks;
|
|
703
|
+
var parse: typeof marked;
|
|
704
|
+
}
|
|
705
|
+
export const options: (options: MarkedOptions) => typeof marked;
|
|
706
|
+
export const setOptions: (options: MarkedOptions) => typeof marked;
|
|
707
|
+
export const use: (...args: MarkedExtension[]) => typeof marked;
|
|
708
|
+
export const walkTokens: <T = void>(tokens: Token[] | TokensList, callback: (token: Token) => T | T[]) => T[];
|
|
709
|
+
export const parseInline: (src: string, optOrCallback?: MarkedOptions | ResultCallback | null | undefined, callback?: ResultCallback | undefined) => string | Promise<string | undefined> | undefined;
|
|
710
|
+
export const parse: typeof marked;
|
|
711
|
+
export const parser: typeof _Parser.parse;
|
|
712
|
+
export const lexer: typeof _Lexer.lex;
|
|
713
|
+
export { _defaults as defaults, _getDefaults as getDefaults } from "defaults";
|
|
714
|
+
export { _Lexer as Lexer } from "Lexer";
|
|
715
|
+
export { _Parser as Parser } from "Parser";
|
|
716
|
+
export { _Tokenizer as Tokenizer } from "Tokenizer";
|
|
717
|
+
export { _Renderer as Renderer } from "Renderer";
|
|
718
|
+
export { _TextRenderer as TextRenderer } from "TextRenderer";
|
|
719
|
+
export { _Slugger as Slugger } from "Slugger";
|
|
720
|
+
export { _Hooks as Hooks } from "Hooks";
|
|
721
|
+
export { Marked } from "Instance";
|
|
722
|
+
export type * from "MarkedOptions";
|
|
723
|
+
export type * from "rules";
|
|
724
|
+
export type * from "Tokens";
|
|
725
|
+
}
|
package/lib/marked.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* marked v7.0.
|
|
2
|
+
* marked v7.0.3 - a markdown parser
|
|
3
3
|
* Copyright (c) 2011-2023, Christopher Jeffrey. (MIT Licensed)
|
|
4
4
|
* https://github.com/markedjs/marked
|
|
5
5
|
*/
|
|
@@ -189,12 +189,14 @@ function splitCells(tableRow, count) {
|
|
|
189
189
|
if (cells.length > 0 && !cells[cells.length - 1].trim()) {
|
|
190
190
|
cells.pop();
|
|
191
191
|
}
|
|
192
|
-
if (
|
|
193
|
-
cells.
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
cells.
|
|
192
|
+
if (count) {
|
|
193
|
+
if (cells.length > count) {
|
|
194
|
+
cells.splice(count);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
while (cells.length < count)
|
|
198
|
+
cells.push('');
|
|
199
|
+
}
|
|
198
200
|
}
|
|
199
201
|
for (; i < cells.length; i++) {
|
|
200
202
|
// leading or trailing whitespace is ignored per the gfm spec
|
|
@@ -627,8 +629,7 @@ class _Tokenizer {
|
|
|
627
629
|
if (cap) {
|
|
628
630
|
const item = {
|
|
629
631
|
type: 'table',
|
|
630
|
-
|
|
631
|
-
// @ts-expect-error
|
|
632
|
+
raw: cap[0],
|
|
632
633
|
header: splitCells(cap[1]).map(c => {
|
|
633
634
|
return { text: c };
|
|
634
635
|
}),
|
|
@@ -636,7 +637,6 @@ class _Tokenizer {
|
|
|
636
637
|
rows: cap[3] && cap[3].trim() ? cap[3].replace(/\n[ \t]*$/, '').split('\n') : []
|
|
637
638
|
};
|
|
638
639
|
if (item.header.length === item.align.length) {
|
|
639
|
-
item.raw = cap[0];
|
|
640
640
|
let l = item.align.length;
|
|
641
641
|
let i, j, k, row;
|
|
642
642
|
for (i = 0; i < l; i++) {
|
|
@@ -836,7 +836,8 @@ class _Tokenizer {
|
|
|
836
836
|
return;
|
|
837
837
|
const nextChar = match[1] || match[2] || '';
|
|
838
838
|
if (!nextChar || !prevChar || this.rules.inline.punctuation.exec(prevChar)) {
|
|
839
|
-
|
|
839
|
+
// unicode Regex counts emoji as 1 char; spread into array for proper count (used multiple times below)
|
|
840
|
+
const lLength = [...match[0]].length - 1;
|
|
840
841
|
let rDelim, rLength, delimTotal = lLength, midDelimTotal = 0;
|
|
841
842
|
const endReg = match[0][0] === '*' ? this.rules.inline.emStrong.rDelimAst : this.rules.inline.emStrong.rDelimUnd;
|
|
842
843
|
endReg.lastIndex = 0;
|
|
@@ -846,7 +847,7 @@ class _Tokenizer {
|
|
|
846
847
|
rDelim = match[1] || match[2] || match[3] || match[4] || match[5] || match[6];
|
|
847
848
|
if (!rDelim)
|
|
848
849
|
continue; // skip single * in __abc*abc__
|
|
849
|
-
rLength = rDelim.length;
|
|
850
|
+
rLength = [...rDelim].length;
|
|
850
851
|
if (match[3] || match[4]) { // found another Left Delim
|
|
851
852
|
delimTotal += rLength;
|
|
852
853
|
continue;
|
|
@@ -862,7 +863,7 @@ class _Tokenizer {
|
|
|
862
863
|
continue; // Haven't found enough closing delimiters
|
|
863
864
|
// Remove extra characters. *a*** -> *a*
|
|
864
865
|
rLength = Math.min(rLength, rLength + delimTotal + midDelimTotal);
|
|
865
|
-
const raw = src.slice(0, lLength + match.index + rLength + 1);
|
|
866
|
+
const raw = [...src].slice(0, lLength + match.index + rLength + 1).join('');
|
|
866
867
|
// Create `em` if smallest delimiter has odd char count. *a***
|
|
867
868
|
if (Math.min(lLength, rLength) % 2) {
|
|
868
869
|
const text = raw.slice(1, -1);
|
|
@@ -1406,7 +1407,10 @@ class _Lexer {
|
|
|
1406
1407
|
return leading + ' '.repeat(tabs.length);
|
|
1407
1408
|
});
|
|
1408
1409
|
}
|
|
1409
|
-
let token
|
|
1410
|
+
let token;
|
|
1411
|
+
let lastToken;
|
|
1412
|
+
let cutSrc;
|
|
1413
|
+
let lastParagraphClipped;
|
|
1410
1414
|
while (src) {
|
|
1411
1415
|
if (this.options.extensions
|
|
1412
1416
|
&& this.options.extensions.block
|
|
@@ -2256,6 +2260,7 @@ class Marked {
|
|
|
2256
2260
|
default: {
|
|
2257
2261
|
if (this.defaults.extensions && this.defaults.extensions.childTokens && this.defaults.extensions.childTokens[token.type]) { // Walk any extensions
|
|
2258
2262
|
this.defaults.extensions.childTokens[token.type].forEach((childTokens) => {
|
|
2263
|
+
// @ts-expect-error we assume token[childToken] is an array of tokens but we can't be sure
|
|
2259
2264
|
values = values.concat(this.walkTokens(token[childTokens], callback));
|
|
2260
2265
|
});
|
|
2261
2266
|
}
|
|
@@ -2335,14 +2340,16 @@ class Marked {
|
|
|
2335
2340
|
if (pack.renderer) {
|
|
2336
2341
|
const renderer = this.defaults.renderer || new _Renderer(this.defaults);
|
|
2337
2342
|
for (const prop in pack.renderer) {
|
|
2338
|
-
const
|
|
2343
|
+
const rendererFunc = pack.renderer[prop];
|
|
2344
|
+
const rendererKey = prop;
|
|
2345
|
+
const prevRenderer = renderer[rendererKey];
|
|
2339
2346
|
// Replace renderer with func to run extension, but fall back if false
|
|
2340
|
-
renderer[
|
|
2341
|
-
let ret =
|
|
2347
|
+
renderer[rendererKey] = (...args) => {
|
|
2348
|
+
let ret = rendererFunc.apply(renderer, args);
|
|
2342
2349
|
if (ret === false) {
|
|
2343
2350
|
ret = prevRenderer.apply(renderer, args);
|
|
2344
2351
|
}
|
|
2345
|
-
return ret;
|
|
2352
|
+
return ret || '';
|
|
2346
2353
|
};
|
|
2347
2354
|
}
|
|
2348
2355
|
opts.renderer = renderer;
|
|
@@ -2350,10 +2357,12 @@ class Marked {
|
|
|
2350
2357
|
if (pack.tokenizer) {
|
|
2351
2358
|
const tokenizer = this.defaults.tokenizer || new _Tokenizer(this.defaults);
|
|
2352
2359
|
for (const prop in pack.tokenizer) {
|
|
2353
|
-
const
|
|
2360
|
+
const tokenizerFunc = pack.tokenizer[prop];
|
|
2361
|
+
const tokenizerKey = prop;
|
|
2362
|
+
const prevTokenizer = tokenizer[tokenizerKey];
|
|
2354
2363
|
// Replace tokenizer with func to run extension, but fall back if false
|
|
2355
|
-
tokenizer[
|
|
2356
|
-
let ret =
|
|
2364
|
+
tokenizer[tokenizerKey] = (...args) => {
|
|
2365
|
+
let ret = tokenizerFunc.apply(tokenizer, args);
|
|
2357
2366
|
if (ret === false) {
|
|
2358
2367
|
ret = prevTokenizer.apply(tokenizer, args);
|
|
2359
2368
|
}
|
|
@@ -2366,21 +2375,23 @@ class Marked {
|
|
|
2366
2375
|
if (pack.hooks) {
|
|
2367
2376
|
const hooks = this.defaults.hooks || new _Hooks();
|
|
2368
2377
|
for (const prop in pack.hooks) {
|
|
2369
|
-
const
|
|
2378
|
+
const hooksFunc = pack.hooks[prop];
|
|
2379
|
+
const hooksKey = prop;
|
|
2380
|
+
const prevHook = hooks[hooksKey];
|
|
2370
2381
|
if (_Hooks.passThroughHooks.has(prop)) {
|
|
2371
|
-
hooks[
|
|
2382
|
+
hooks[hooksKey] = (arg) => {
|
|
2372
2383
|
if (this.defaults.async) {
|
|
2373
|
-
return Promise.resolve(
|
|
2384
|
+
return Promise.resolve(hooksFunc.call(hooks, arg)).then(ret => {
|
|
2374
2385
|
return prevHook.call(hooks, ret);
|
|
2375
2386
|
});
|
|
2376
2387
|
}
|
|
2377
|
-
const ret =
|
|
2388
|
+
const ret = hooksFunc.call(hooks, arg);
|
|
2378
2389
|
return prevHook.call(hooks, ret);
|
|
2379
2390
|
};
|
|
2380
2391
|
}
|
|
2381
2392
|
else {
|
|
2382
|
-
hooks[
|
|
2383
|
-
let ret =
|
|
2393
|
+
hooks[hooksKey] = (...args) => {
|
|
2394
|
+
let ret = hooksFunc.apply(hooks, args);
|
|
2384
2395
|
if (ret === false) {
|
|
2385
2396
|
ret = prevHook.apply(hooks, args);
|
|
2386
2397
|
}
|