do not render in async mode

This commit is contained in:
James Brumond 2023-05-18 21:56:18 -07:00
parent 1dcc58c4b2
commit 865016bb26
Signed by: james
GPG Key ID: E8F2FC44BAA3357A

View File

@ -26,24 +26,23 @@ export interface MarkdownExtension {
}
export async function render_markdown_to_html(markdown: string, options: MarkdownOptions = { }) {
const marked_options = marked_opts(true, options);
const marked_options = marked_opts(options);
const unsafe_html = options.inline
? marked.parseInline(markdown, marked_options)
: await marked.parse(markdown, marked_options).then(resolve_async_bindings);
: marked.parse(markdown, marked_options);
return sanitize_html(unsafe_html, options.custom_elements);
return sanitize_html(await resolve_async_bindings(unsafe_html), options.custom_elements);
}
export function render_markdown_to_html_inline_sync(markdown: string, options: MarkdownOptions = { }) {
const marked_options = marked_opts(false, options);
const marked_options = marked_opts(options);
setup_marked(options, marked_options);
const unsafe_html = marked.parseInline(markdown, marked_options);
return sanitize_html(unsafe_html, options.custom_elements);
}
function marked_opts<T extends boolean>(async: T, options: MarkdownOptions) : marked.MarkedOptions & { async: T } {
function marked_opts<T extends boolean>(options: MarkdownOptions) : marked.MarkedOptions {
return {
async,
breaks: options.breaks || false,
renderer: create_renderer(options),
mangle: false,