Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
asimpletune opened this issue Aug 18, 2024 · 3 comments

Comments

@asimpletune
Copy link

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

@cossssmin
Copy link
Member

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
Copy link
Author

asimpletune commented Aug 18, 2024

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
Copy link
Member

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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants