3

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 2

4

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);
Sign up to request clarification or add additional context in comments.

Comments

0

This method will parse an input string and return a list of block tokens.

var md     = window.markdownit();
var result = md.parse( document.querySelector('#markdown-content').textContent, {} );

See https://markdown-it.github.io/markdown-it/#MarkdownIt.parse

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.