Reading:
Convert Markdown to HTML in javascript

Convert Markdown to HTML in javascript

Metamug
Convert Markdown to HTML in javascript

Converting markdown to JS in browser

Markdown sent in the browser can be converted into html and appended into the DOM. The other method is to use a library like parsedown in PHP and convert the markdown to HTML on the server.

Understand the difference between client side rendering and server side rendering

Using Showdown JS

https://github.com/showdownjs/showdown

<div class="article" id="article-section"></div>
<script type="text/javascript" src="https://unpkg.com/showdown/dist/showdown.min.js"></script>

Here we are trying to load the markdown in the page from the server using PHP.

const htmlContent = document.createElement("div");
var converter = new showdown.Converter(),
text      = '<?php //echo str_replace("\n",'\\n',addslashes($markdown)); ?>';
htmlContent.innerHTML=converter.makeHtml(text);
document.getElementById('article-section').appendChild(htmlContent)


Icon For Arrow-up
Comments

Post a comment