Showdown doesn't parse inside html block

1k Views Asked by At

I am using Showdown.

When I run this code:

const showdown = require("showdown")

converter = new showdown.Converter()
const myMarkdownText = '## Some important text'
const myHtmlText = converter.makeHtml(myMarkdownText)

I get

<h2 id="someimportanttext">Some important text</h2>

which is the expected result.

But when I run this code:

const showdown = require("showdown")

converter = new showdown.Converter()
const myMarkdownText = '<div markdown = "1"> ## Some important text </div>'
const myHtmlText = converter.makeHtml(myMarkdownText)

I get

<div markdown = "1"><p>## Some important text </p></div>

Which means that Showdown didn't parse the stuff inside the html div.

Any help on how to make it work?

2

There are 2 best solutions below

2
Wezelkrozum On

After reading the Showdown documentation (https://github.com/showdownjs/showdown#valid-options) my conclusion is that you should probably enable the backslashEscapesHTMLTags option and backslash the html tags.

0
klovaaxel On

A bit late but for future reference:

To enable parsing of markdown inside HTML tags you have to put markdown="1" as a property on the HTML tag like:

<div markdown="1"># I will be parsed</div>

There is more information in the documentation