How do I use markdown-it.js to parse content in a div?

Viewed 1891

I'm trying to figure out how to parse markdown content that is already in a div:

<div id="markdown-content">
 ## Heading
</div>  

I've been looking at jquery markdown parsers on github such Markdown-it, but can't find any with docs that show how to parse existing content. Markdown-it.js seems to be popular, but their only browser usage example is:

var md = window.markdownit();
var result = md.render('# markdown-it rulezz!');

I'm not sure how to apply that to parsing content that's already in a div, is it possible to do this in a simple way?

2 Answers

All you have to do is get the markdown text and parse it. Then put it somewhere. You could even put it back where you got it from.

var markdown = $('#markdown-content').html();
var html = md.render(markdown);
$('#output').html(html);
Related