exported `markdown` function is async, but doesn't return a `Promise` in function signature
- Maizzle Version: 4.8.9
- Node.js Version: 16.20.2
I was trying to use the markdown function that Maizzle exports, but it doesn't really seem to be doing anything. In my test code I added some print debug statements and I discovered that a promise is being returned instead of a string. Here's the example code and it's output:
const mdInput = `# hello, world!`
const awaited_html = await markdown(mdInput, { html: true })
console.log(awaited_html)
const html = markdown(mdInput, { html: true })
console.log(html)
# hello, world!
Promise { <pending> }
The function signature I see for markdown is
/**
Compile Markdown to HTML.
@param {string} input String to compile with Markdown.
@param {Options} [options] markdown-it options.
*/
function markdown(input: string, options?: MarkdownItOptions): string;
You can see that in the typescript code the function is synchronous, but at runtime it's returning a promise.
My deeper issue is that # hello, world! isn't being compiled to html at all.
The markdown you pass to it needs to be wrapped in a <md> tag or one of the other landmarks, see the docs again:
https://maizzle.com/docs/transformers/markdown#api
I’ll have a look at the types, yes.
And I think for Maizzle 5 we can look at not requiring the wrapping tags, though that would just turn it into a glorified markdown renderer when in fact we want to expose the Markdown Transformer.
The markdown you pass to it needs to be wrapped in a
tag or one of the other landmarks, see the docs again
Thank you for pointing that out, very helpful.
You'll be able to pass a markdown string with or without the <md> wrapping tags in Maizzle 5:
https://next.maizzle.com/docs/markdown#api
I'll also fix the type definition for it in v4 👍