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.