markdown-to-html-pipe
markdown-to-html-pipe copied to clipboard
MarkdownToHtml pipe shouldn't add additional HTML
Currently, when using the pipe the output HTML markup is wrapped in a <p>
HTML paragraph.
Actual Output
<span>
<p>
foo <strong>bar</strong>
</p>
</span>
Imho the expected behaviour is not to add any additional HTML.
Expected Output
<span>
foo <strong>bar</strong>
</span>
In my case it made the layout change since I had some span text before which is now in a paragraph and became a block element.
Input
<span [innerHTML]="'foo **bar**' | MarkdownToHtml"></span>
Hi @takahser. Thanks for your report.
Unfortunetly the p
-tag comes from marked and thus cannot be removed.
As a workaround you could set a class on your span
to inline inner paragraphs.
.inline p {
display: inline;
}
@vknabel I took a look at the documentation for marked and noticed there is a way to output inline. They provide an inline lexer for this purpose. I am including the update in your code below, perhaps you can allow an option in your pipe to allow for inline output or with a wrapping p tag.
MarkdownToHtmlPipe.prototype.transform = function (markdown, options) {
if (markdown == null)
return '';
return marked.inlineLexer(markdown, [], options);
};
Found the information here: https://github.com/markedjs/marked/issues/395