javascriptmarkdownpagedownshowdown

Markdown converters not working for me?


I am using markdown-js to convert Markdown to HTML however it is not giving expected output.

HTML:

<p class="markdown">
# Highlight.js

---

Some more text here...
</p>

JavaScript:

$('.markdown').each(function(){
    var html = markdown.toHTML($(this).html());     
    console.log(html);
    $(this).html(html);
});

Output:

<pre><code>
# Highlight.js
---
Some more text here...
</code></pre>

So it simply surrounded provided Markdown text with <pre><code> instead of output like below:

<h1>Highlight.js</h1>
<hr>
<p>Some more text here...</p>

In fact I also tried other libraries such as showdown, pagedown, etc but output was always:

<pre><code>
# Highlight.js
---
Some more text here...
</code></pre>

Can anyone have an idea of what I am missing here ? Thanks


Solution

  • Your code works for me ... plunk

    What I've noticed though is that if the markdown is indented it does not parse correctly.

    this works

    <p class="markdown">
    # Highlight.js
    
    ---
    
    Some more text here...
    </p>
    

    indented doesn't

    <p class="markdown">
        # Highlight.js
    
        ---
    
        Some more text here...
    </p>