maizzle / framework

Quickly build HTML emails with Tailwind CSS.
https://maizzle.com
MIT License
1.24k stars 49 forks source link

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

Open asimpletune opened 2 months ago

asimpletune commented 2 months ago

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.

cossssmin commented 2 months ago

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.

asimpletune commented 2 months ago

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.

cossssmin commented 2 months ago

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 👍