Skip to content

Extra tag <p> generated if there is empty line above in some cases. #1058

Open

Description

@jcyrss

test with pulldown-cmark version : 0.13.0


The markdown content used in this testing is as the following:

## title 1

See the following example:

<iframe srcdoc='

<head>
  <style>

.wrapper  {
  border: 1px solid teal;
}
  </style>
</head>

<body>  

<div class="wrapper">  

  <div>1</div>

  <div>2</div>

</div>

</body>

'></iframe>

After converting (without enable any options) by pulldown-cmark, the result is as the following

Image

We could see, extra <p> tags are put there.

For both 2 cases, if I delete the above empty line (line 9 and 27), that issue will be gone.




Anther simpler example

## title 1

See the following example:

<section>
    
    <div>hello world</div>   
</section>

The converting result is as the following.

Image

It seems empty line in HTML blocks will trigger the problem like that.

Activity

  1. ehuss commented on Oct 30, 2025

    @ehuss
    Contributor

    I believe this is normal behavior for commonmark. Certain kinds of HTML Blocks end when there is a blank line. Once it ends, any text will be a normal markdown element, and get processed like normal markdown such as adding <p> tags. The solution is to remove the blank lines.

  2. jcyrss commented on Oct 30, 2025

    @jcyrss
    Author

    I believe this is normal behavior for commonmark. Certain kinds of HTML Blocks end when there is a blank line. Once it ends, any text will be a normal markdown element, and get processed like normal markdown such as adding <p> tags. The solution is to remove the blank lines.

    But that's inside of HTML snippet. It should be kept untouched.

  3. ehuss commented on Oct 30, 2025

    @ehuss
    Contributor

    If you're saying it's part of the html attribute string srcdoc, commonmark specifically does not allow blank lines (attribute value specification).

  4. jcyrss commented on Nov 1, 2025

    @jcyrss
    Author

    If you're saying it's part of the html attribute string srcdoc, commonmark specifically does not allow blank lines (attribute value specification).


    Not just those in attribute srcdoc. Even normal HTML snippet, that issue still exists.

    See this markdown content,

    ## title 1
    
    See the following example:
    
    <section>
        
        <div>hello world</div>   
    </section>

    The converting result is as the following

    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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