Šime Vidas Šime Vidas - 7 months ago 33
Markdown Question

How to prevent Markdown from wrapping the generated HTML in a <p> element?

Update: The bounty is for a solution using the “marked” library.

This Markdown code:


will produce this HTML code:


Live demo: https://jsbin.com/luganot/edit?js,console

However, I'm already injecting the generated HTML code into an inline context, like so:

<p> text [inject generated HTML here] text </p>

so I don't want the
element to wrap around the generated HTML code. I just want the
delimiters to be converted to an
, element, and so on.

Is there a way to tell the Markdown converter to not produce the
wrapper? Currently, I'm doing a
on the generated HTML string, which does remove the
, and
tags, but this is obviously not a solution I'd like to keep for the long-term.

Answer Source

You can skip the block-lexing part and use inlineLexer instead.

html = marked.inlineLexer(markdown, [], options);

marked.inlineLexer('*foo*', []) // will output '<em>foo</em>'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download