Skip to content

Standard Extensions add extra LF character to html #1003

Closed

Description

@flywire

Extra linefeed characters are shown after code blocks in the html file. The extra white space is carried over to mkdocs but it does not affect rendering.

index.md

python test

```python
pass
```

Next test
```
random
```

html test
```html
<p>empty</p>
```
end

python -m markdown .\docs\index.md >index.html

<p>python test</p>
<p><code>python
pass</code></p>
<p>Next test
<code>random</code></p>
<p>html test
<code>html
&lt;p&gt;empty&lt;/p&gt;</code>
end</p>

With extra extension:

python -m markdown -x extra .\docs\index.md >index.html

<p>python test</p>
<pre><code class="python">pass
</code></pre>

<p>Next test</p>
<pre><code>random
</code></pre>

<p>html test</p>
<pre><code class="html">&lt;p&gt;empty&lt;/p&gt;
</code></pre>

<p>end</p>

With extra and codehilite extension:

python -m markdown -x extra -x codehilite .\docs\index.md >index.html

<p>python test</p>
<div class="codehilite"><pre><span></span><code><span class="k">pass</span>
</code></pre></div>


<p>Next test</p>
<div class="codehilite"><pre><span></span><code><span class="err">random</span>
</code></pre></div>


<p>html test</p>
<div class="codehilite"><pre><span></span><code><span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>empty<span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
</code></pre></div>


<p>end</p>

Activity

  1. waylan commented on Jul 17, 2020

    @waylan
    Member

    This is the correct behavior. A code block should always end with a line break.

    Note, however, that you are using fence code blocks, which are a non-standard feature. In your first example, you have not activated the fenced_code extension and the code blocks are being parsed as code spans. Of course, code spans have whitespace striped from the ends as required by the rules. Therefore, the behavior is different there.

    In your other two examples, you have activated the extra extension, which includes fenced_code. Therefore, the blocks are parsed as fenced code blocks and the line break is preserved.

    I'm closing this as there is no issue here.

  2. added
    invalid
    on Jul 17, 2020
  3. flywire commented on Jul 17, 2020

    @flywire
    Author

    Wouldn't that require a line break to divide </pre></div> in the last example rather than the double line break after it now?

  4. waylan commented on Jul 18, 2020

    @waylan
    Member

    Wouldn't that require a line break to divide in the last example rather than the double line break after it now?

    First of all, the output of the codehilite extension is generated by Pigments. We simply pass through what Pigments provides. Therefore, of there was an issue it would need to be addressed upstream.

    Second, adding a line break there would make no difference. As that is outside of the <pre> tag, the browser would render using 'normal" behavior. Specifically, all whitespace is collapsed to a single space. In other words, adding a newline would result in a single space. As it stands now, the two lines after the <div> are rendered as a single space. The only reason any space would appear between the <div> and the <p> that follows it would be because margin and/or padding are defined in CSS on one or both of those elements. The whitespace in the markup is completely insignificant.

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

    invalid

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions