markdown-to-html-pipe icon indicating copy to clipboard operation
markdown-to-html-pipe copied to clipboard

MarkdownToHtml pipe shouldn't add additional HTML

Open takahser opened this issue 5 years ago • 2 comments

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>

takahser avatar Nov 10 '19 21:11 takahser

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 avatar Nov 11 '19 07:11 vknabel

@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

larqitos avatar Nov 22 '19 18:11 larqitos