ivo Welch ivo Welch - 1 month ago 23
Markdown Question

markdown in browser via showdown

I am wondering whether I can create my new website in markdown instead of in html. showdown.js at https://github.com/coreyti/showdown seems to be a plugin that can do this.

I am thinking something like

<html>
<head>
<script type="text/javascript" src="/js/showdown-starter.js" />
<link rel="StyleSheet" href="mystylesheet.css" type="text/css" />
</head>

<body>

# Welcome

Hello. Welcome to my website.

</body>
</html>


Presumably, the client javascript would transform this into html that the browser likes.

Answer

Sure you can.

Here's an example how:

<div id="content">
# Welcome

Hello.  Welcome to my **website**.
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/1.4.0/showdown.min.js"></script>
<script>
var conv = new showdown.Converter();
var txt = document.getElementById('content').innerHTML;
console.log(txt);
document.getElementById('content').innerHTML = conv.makeHtml(txt);
</script>