Skip to content

Html blocks not wrapped in <p/> when escapeHtml set to true #78

@evpaassen

Description

@evpaassen

I'm using the Parser/HtmlRenderer combo with escapeHtml(true), but this leaves html blocks without being wrapped in a paragraph tag. Please see the following example. It seems like incorrect behaviour to me.

Parsing code

public String render(String text) {
    Parser parser = Parser.builder().build();
    HtmlRenderer renderer = HtmlRenderer.builder().escapeHtml(true).build();
    Node document = parser.parse(text);
    return renderer.render(document);
}

Input

This is a paragraph.

This is a paragraph.

<div>html here</div>

This is a paragraph.

This is a paragraph.

<strong>html here</strong>

This is a paragraph.

This is a paragraph.

<p>html here</p>

This is a paragraph.

Expected output

<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>&lt;div&gt;html here&lt;/div&gt;</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>&lt;strong&gt;html here&lt;/strong&gt;</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>&lt;p&gt;html here&lt;/p&gt;</p>
<p>This is a paragraph.</p>

Actual output

<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
&lt;div&gt;html here&lt;/div&gt;
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>&lt;strong&gt;html here&lt;/strong&gt;</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
&lt;p&gt;html here&lt;/p&gt;
<p>This is a paragraph.</p>

Note that the line <strong>html here</strong> actually is wrapped, but the other two aren't.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions