27

I just saw this

    Lorem ipsum

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec id vestibulum justo. Aenean ac diam id nisl bibendum porta.

Renders on my chrome (73.0.3683.86) as Code block

I'm (having zero familiarity with HTML) assuming the floating scroll bar and only applying to half of the code block are bugs?

7
  • 9
    renders the same on my firefox, fwiw
    – Brandon_J
    Commented Apr 6, 2019 at 23:54
  • Same on up-to-date chrome Commented Apr 7, 2019 at 0:01
  • Same on latest Safari. Commented Apr 7, 2019 at 0:09
  • related: meta.stackoverflow.com/questions/382183/…
    – Luuklag
    Commented Apr 8, 2019 at 6:34
  • 3
    FWIW, the HTML generated by the SE Markdown parser is <p><pre> Lorem ipsum</p> <pre><code>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec id vestibulum justo. Aenean ac diam id nisl bibendum porta. </code></pre> <p></pre></p>. That's pretty broken by any standards. Commented Apr 8, 2019 at 10:21
  • 2
    That generated html looks almost as broken as the html generated by Confluence.
    – luk2302
    Commented Apr 8, 2019 at 10:30
  • @luk2302 I've just started using Confluence for work reasons, and that truth burns. Commented Apr 12, 2019 at 3:52

2 Answers 2

8

The behavior that results from indenting the start of a HTML block is undefined. From the documentation:

Block-level HTML elements have a few restrictions:

  1. They must be separated from surrounding text by blank lines.
  2. The begin and end tags of the outermost block element must not be indented.
  3. Markdown can't be used within HTML blocks.

(emphasis mine)

The actual behavior in this case is... Weird: the <pre> block is still allowed and passed through to the result, but the contents of the block are also parsed as Markdown and rendered accordingly - so you get another <pre> block and some paragraphs nested in the outer block.

This behavior was previously noted on MSE: Code block markdown formatting using <pre>

I'm leaving this marked as a bug because the behavior is inconsistent both with what the documentation implies and with what we should expect future versions of the rendering engine to support - in other words, this behavior is generally undesirable and should not be relied on even when it is desirable.

15

Yeah it is a bug.

The reason is the leading whitespace of the <pre>:

 <pre>
^

Also interesting, backticks (with leading whitespace) have problems too:

`test`, `<pre>`, ` test`, ` <pre>`

Renders in comments (totally wrong):

Rendered Picture

Renders in answer block (white space is missing):

test, <pre>, test, <pre>

3

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .