4

I came across this answer which appeared to have rendered incorrectly.

enter image description here

Editing it, the answer looked fine in preview so I suspected it just needed to be rerendered, but this was not the case. The answer did show one initial error in that solution was surrounded by two <h1> tags. I fixed the closing tag, and still looked fine in preview:

enter image description here

But, on saving the edit, the published question was still improperly rendered, as before.

The solution was to remove the ------ Markdown underline from below the title. As the underline is supposed to render the preceding text as <h2>, I assume there is some kind of conflict but, as you can see, this issue affects not only the title but the following paragraph.

My question is, why is this causing the published answer to not render correctly even when it is correct in preview, and can this be prevented?

4

1 Answer 1

1

As an aside about Markdown formatting, and correcting it in malformed posts:

Always, always, always add empty lines between Markdown formatting constructs. In my experience, when there's a formatting issue or something rendering in an unexpected fashion in a post, it very often results from a lack of line breaks between distinct syntax elements, be that fenced code blocks ```, lists, headers, or a horizontal rule -----, as in this case.

From the syntax shown in the post:

<h1>Solution</h1>
-----
1. Testing

Solution

----- 1. Testing

Versus with empty lines between elements:

<h1>Solution</h1>

-----

1. Testing

Solution


  1. Testing

Also, on the subject of headings, it should be noted that the Markdown heading equivalent of an HTML <hX> tag is X # characters in front of the heading text:

<h1>Title 1</h1>

# Title 1

<h2>Title 2</h2>

## Title 2

<h3>Title 3</h3>

### Title 3

Title 1

Title 1

Title 2

Title 2

Title 3

Title 3

Or adding one or more equals === (for h1) or hyphens --- (for h2) immediately below a line of text, called alternative heading syntax on the Markdown guide (possibly the syntax OP was going for?):

Title 1
=======

Title 2
-------

Title 1 =======

Title 2


Edit: It appears that the preview gets the alternative header syntax right, but that the actual post doesn't, highlighting the exact issue your Q mentioned!
Either that syntax is supported, or it isn't, but it definitely shouldn't show accurately in the preview and then fail to render on the post.

5
  • Your last example actually has the exact problem this question is asking about - it renders properly in the edit preview but not in the actual post. Commented Sep 8, 2020 at 22:21
  • @JohnMontgomery Shows how silly I am- I didn't even bother to check after it posted. You're right!
    – zcoop98
    Commented Sep 8, 2020 at 22:23
  • The very first block does as well. In preview it simply omits the horizontal rule and doesn't display the hyphens.
    – zcoop98
    Commented Sep 8, 2020 at 22:24
  • Per a comment from an SO dev on this answer , this just looks like a similar issue where the "client-side markdown renderer is behaving differently than [the] server-side renderer." I appreciate that it's not hard to fix the formatting or avoid the problem, the only issue was that the OP obviously wrote it, went to the trouble of formatting it, but was caught out because of sub-optimal WYSIWYGiness.
    – David Buck
    Commented Sep 8, 2020 at 22:50
  • @DavidBuck Agreed, it's suboptimal for everyone involved. It does appear that it's already been recognized by SO per your link though, which is nice. No updates since that was posted, but it's only been a month.
    – zcoop98
    Commented Sep 8, 2020 at 23:21

You must log in to answer this question.

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