Skip to content

Contents of <pre> tags wrapped in <div> tags are not left alone if they contain empty lines #807

@aral

Description

@aral

Contents of HTML preformatted text blocks (<pre>…</pre>) are, correctly, left alone:

e.g.,

<pre>a

b
</pre>

is rendered correctly as, with the contents untouched:

<pre>a

b
</pre>

However, if you wrap that in a <div>:

<div>
  <pre>a

  b
  </pre>
</div>

the commonmark parser starts parsing the contents of the <pre> tag following the empty line, which corrupts the resulting HTML:

<div>
  <pre>a
<p>b
</pre></p>
</div>

Notice the erroneously added <p> tag prior to b that closes following the </pre> tag.

I encountered this in Markdown-it and was able to narrow it down to this test case which is also reproducible in the commonmark parser at https://spec.commonmark.org/dingus/.

Related:

markdown-it/markdown-it#238

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