mirror of
https://github.com/markedjs/marked.git
synced 2026-11-30 16:48:05 +01:00
fix: ignore async: false when async: true is set by an extension (#2920)
This commit is contained in:
@@ -244,6 +244,16 @@ export class Marked {
|
||||
|
||||
const origOpt = { ...optOrCallback };
|
||||
const opt = { ...this.defaults, ...origOpt };
|
||||
|
||||
// Show warning if an extension set async to true but the parse was called with async: false
|
||||
if (this.defaults.async === true && origOpt.async === false) {
|
||||
if (!opt.silent) {
|
||||
console.warn('marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored.');
|
||||
}
|
||||
|
||||
opt.async = true;
|
||||
}
|
||||
|
||||
const throwError = this.#onError(!!opt.silent, !!opt.async, callback);
|
||||
|
||||
// throw error in case of non string input
|
||||
|
||||
@@ -577,6 +577,20 @@ used extension2 walked</p>
|
||||
expect(defaults.async).toBeFalse();
|
||||
});
|
||||
|
||||
it('should return Promise if async', () => {
|
||||
expect(marked('test', { async: true })).toBeInstanceOf(Promise);
|
||||
});
|
||||
|
||||
it('should return string if not async', () => {
|
||||
expect(typeof marked('test', { async: false })).toBe('string');
|
||||
});
|
||||
|
||||
it('should return Promise if async is set by extension', () => {
|
||||
use({ async: true });
|
||||
|
||||
expect(marked('test', { async: false })).toBeInstanceOf(Promise);
|
||||
});
|
||||
|
||||
it('should allow deleting/editing tokens', () => {
|
||||
const styleTags = {
|
||||
extensions: [{
|
||||
|
||||
Reference in New Issue
Block a user