-
-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Clear and concise description of the problem
Thanks for this excellent tool! I'm currently using it with VitePress 2.0.0-alpha and trying to create my own markdown-it plugin that requires an async render rule. However, it seems that md.renderer.rules does not support async functions.
Would it be possible to allow md.renderer.rules to be async to support this use case?
Thanks in advance!
Suggested solution
We can extend the Renderer class and create the async render method in this repo.
AsyncRenderer.prototype.render = async function (tokens, options, env) {
let result = '';
const rules = this.rules;
const codes = await Promise.all(
tokens.map(async (token, i) => {
const type = token.type;
if (type === 'inline') {
return this.renderInline(token.children, options, env);
} else if (typeof rules[type] !== 'undefined') {
return rules[type](tokens, i, options, env, this);
} else {
return this.renderToken(tokens, i, options, env);
}
}),
);
result = codes.join('');
return result;
}
Alternative
No response
Additional context
the sample code is adjusted from this
https://github.com/markdown-it/markdown-it/blob/master/lib/renderer.mjs
Validations
- Follow our Code of Conduct
- Read the Contributing Guide.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request