Categories
JavaScript Answers

How to convert Markdown to HTML with JavaScript?

Spread the love

Sometimes, we want to convert Markdown to HTML with JavaScript.

In this article, we’ll look at how to convert Markdown to HTML with JavaScript.

How to convert Markdown to HTML with JavaScript?

To convert Markdown to HTML with JavaScript, we can use the showdown library.

For instance, we write

<script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/2.1.0/showdown.min.js"></script>

to add the showdown library with a script tag.

Then we write

const converter = new showdown.Converter();
const text = "# hello, markdown!";
const html = converter.makeHtml(text);

to create a showdown.Converter convert object.

Then we call makeHtml on it with the Markdown text to convert it to html.

Conclusion

To convert Markdown to HTML with JavaScript, we can use the showdown library.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.