@@ -21,8 +21,8 @@ export class Marked {
21
21
defaults = _getDefaults ( ) ;
22
22
options = this . setOptions ;
23
23
24
- parse = this . # parseMarkdown( _Lexer . lex , _Parser . parse ) ;
25
- parseInline = this . # parseMarkdown( _Lexer . lexInline , _Parser . parseInline ) ;
24
+ parse = this . parseMarkdown ( _Lexer . lex , _Parser . parse ) ;
25
+ parseInline = this . parseMarkdown ( _Lexer . lexInline , _Parser . parseInline ) ;
26
26
27
27
Parser = _Parser ;
28
28
Renderer = _Renderer ;
@@ -514,22 +514,25 @@ export class Marked {
514
514
return _Parser . parse ( tokens , options ?? this . defaults ) ;
515
515
}
516
516
517
- #parseMarkdown( lexer : ( src : string , options ?: MarkedOptions ) => TokensList | Token [ ] , parser : ( tokens : Token [ ] , options ?: MarkedOptions ) => string ) {
518
- return ( src : string , options ?: MarkedOptions | undefined | null ) : string | Promise < string > => {
517
+ private parseMarkdown ( lexer : ( src : string , options ?: MarkedOptions ) => TokensList | Token [ ] , parser : ( tokens : Token [ ] , options ?: MarkedOptions ) => string ) {
518
+ type overloadedParse = {
519
+ ( src : string , options : MarkedOptions & { async : true } ) : Promise < string > ;
520
+ ( src : string , options : MarkedOptions & { async : false } ) : string ;
521
+ ( src : string , options ?: MarkedOptions | undefined | null ) : string | Promise < string > ;
522
+ } ;
523
+
524
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
525
+ const parse : overloadedParse = ( src : string , options ?: MarkedOptions | undefined | null ) : any => {
519
526
const origOpt = { ...options } ;
520
527
const opt = { ...this . defaults , ...origOpt } ;
521
528
522
- // Show warning if an extension set async to true but the parse was called with async: false
523
- if ( this . defaults . async === true && origOpt . async === false ) {
524
- if ( ! opt . silent ) {
525
- console . warn ( 'marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored.' ) ;
526
- }
529
+ const throwError = this . onError ( ! ! opt . silent , ! ! opt . async ) ;
527
530
528
- opt . async = true ;
531
+ // throw error if an extension set async to true but parse was called with async: false
532
+ if ( this . defaults . async === true && origOpt . async === false ) {
533
+ return throwError ( new Error ( 'marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise.' ) ) ;
529
534
}
530
535
531
- const throwError = this . #onError( ! ! opt . silent , ! ! opt . async ) ;
532
-
533
536
// throw error in case of non string input
534
537
if ( typeof src === 'undefined' || src === null ) {
535
538
return throwError ( new Error ( 'marked(): input parameter is undefined or null' ) ) ;
@@ -573,9 +576,11 @@ export class Marked {
573
576
return throwError ( e as Error ) ;
574
577
}
575
578
} ;
579
+
580
+ return parse ;
576
581
}
577
582
578
- # onError( silent : boolean , async : boolean ) {
583
+ private onError ( silent : boolean , async : boolean ) {
579
584
return ( e : Error ) : string | Promise < string > => {
580
585
e . message += '\nPlease report this to https://github.com/markedjs/marked.' ;
581
586
0 commit comments