Skip to content

Void phrasing elements (br, embed, img, input and wbr) not wrapped in <p> when standalone #806

@Songmu

Description

@Songmu

HTML includes void elements (elements without closing tags). Among these, the behavior of phrasing content (inline elements) when written in raw HTML is undefined in CommonMark.

Void elements are documented at https://developer.mozilla.org/en-US/docs/Glossary/Void_element. Within this, the following four are phrasing content:

  • br
  • embed
  • img
  • input
  • wbr

When these elements appear alone, Markdown should treat them as elements within a paragraph. However, the current reference implementation does not do this.

input

<img src="https:/example.com/image.png" alt="An image" title="Image title" />

<input type="text" name="name" value="value">

<br>

<wbr />

current actual output

<img src="https:/example.com/image.png" alt="An image" title="Image title" />
<input type="text" name="name" value="value">
<br>
<wbr />

expected output

<p><img src="https:/example.com/image.png" alt="An image" title="Image title" /></p>
<p><input type="text" name="name" value="value"></p>
<p><br></p>
<p><wbr /></p>

Why I think these should be wrapped in p elements

Currently, standalone Markdown image element or two or more consecutive raw <br> elements are wrapped in a <p> element. Therefore, for consistency, I believe these void elements should also be wrapped when they appear alone.

input

![img.png](https://example.com/img.png)

<br><br>

current output

<p><img src="https://example.com/img.png" alt="img.png"></p>

<p><br><br></p>

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