-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async and hooks extensions not working together #2919
Comments
the Maybe we should throw an error in this case before trying to parse, but I think this is a clear case of invalid way of using marked. |
Thanks for the answer, I know that it is not actually using async extensions, but by using Aside from a better error message, it would be great to have a way to get marked working in a sync way skipping async extensions, but that's up to you. |
I don't understand what you mean skipping async extensions? are you saying you want marked to skip the highlight extensions because it is async and the request was for async = false? We already have way accomplish this by using instances. You can create one marked instance with async extensions and one with only sync extensions. Then just call the one you want: import { Marked } from 'marked';
const syncMarked = new Marked();
const asyncMarked = new Marked();
syncMarked.use(gfmHeadingId());
asyncMarked.use(gfmHeadingId());
asyncMarked.use(markedHighlight(...));
console.log(syncMarked.parse('...'));
asyncMarked.parse('...').then(html => console.log(html)); |
I guess I'll use it this way then. Thanks for the help! |
Marked version:
6.0.0
Describe the bug
I have recently updated marked to version
6.0.0
. I had to installmarked-gfm-heading-id
to use heading links, and that caused my app to crash with the following error:src.replace is not a function
.Turns out that this is caused by an attempt to render markdown using
{ async: false }
together with an async extension and one that uses hooks. Here's why:this.defaults
inmarked
class hasasync
set to true,Instance.ts
, line 256, markdown is preprocessed,Instance.ts
, line 178,this.defaults.async
makes the preprocesser return aPromise
instead of astring
.It seems like the problem is that the
optOrCallback
passed toparse
do not end up affecting the preprocess.Demo here: https://codesandbox.io/s/marked-async-hooks-bug-7t8wkp?file=/src/index.js:63-84
Expected behavior
App should not crash
The text was updated successfully, but these errors were encountered: