framework icon indicating copy to clipboard operation
framework copied to clipboard

exported `markdown` function is async, but doesn't return a `Promise` in function signature

Open asimpletune opened this issue 1 year ago • 3 comments

  • 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.

asimpletune avatar Aug 18 '24 09:08 asimpletune

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.

cossssmin avatar Aug 18 '24 10:08 cossssmin

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.

asimpletune avatar Aug 18 '24 11:08 asimpletune

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 👍

cossssmin avatar Aug 29 '24 14:08 cossssmin