7

There seems to be some problem with the handling of links after <h1></h1>. It wasn't there some months ago. The problem is here and on the main site (I've noticed because I opened an old answer of mine and the first thing I thought was that it had been defaced). The problem sees to exist if I have some links in the form <h1></h1>[Text](http://link.com) with the <h1> in the beginning of the line (??). So x<h1>d</h1>[Text](http://link.com) works correctly (??).

Example text 1 Some text... Correctly formatted hyperlink

Example text 2

Some text... [Not correctly formatted hyperlink](https://stackoverflow.com)

x

Example text 3

Some text... Correctly formatted hyperlink

3
  • 2
    The CommonMark parser is picky when you mix regular html and mark down. An extra line or space does change the render behavior.
    – rene
    Commented Jan 13, 2021 at 21:02
  • @rene So this one... Ok... My response is in the 4% that isn't rendered correctly... I haven't posted a link to the problematic post I have because I didn't want to advertise it.
    – xanatos
    Commented Jan 13, 2021 at 21:08
  • Yeah, I have done some work on finding the 4% troublesome posts but it is tricky to find them without having a ton of false positives.
    – rene
    Commented Jan 13, 2021 at 21:10

1 Answer 1

9

Do not mix html and markdown.

This is maybe not what you hoped for but instead of trying to find / fix these mishaps with code / parsing I think it is better to have some recipes to fix the posts that are still out in the wild. A capable human is probably better equipped to deal with all the quirks between the client and server side implementation and the CommonMark specification.

Here is the recipe to fix the case you've found:

Example text 1 Some text... Correctly formatted hyperlink

Example text 2

Some text... Not correctly formatted hyperlink

Example text 3

Some text... Correctly formatted hyperlink

Markdown

Example text 1 Some text... [Correctly formatted hyperlink](https://stackoverflow.com)

# Example text 2
Some text... [Not correctly formatted hyperlink](https://stackoverflow.com)

# Example text 3
Some text... [Correctly formatted hyperlink](https://stackoverflow.com)

Alternative


Example text 1 Some text... Correctly formatted hyperlink

Example text 2

Some text... Not correctly formatted hyperlink

x

Example text 3

Some text... Correctly formatted hyperlink

Markdown

Example text 1 Some text... [Correctly formatted hyperlink](https://stackoverflow.com)

<h1>Example text 2</h1> Some text... <a href="https://stackoverflow.com">Not correctly formatted hyperlink</a>

x<h1>Example text 3</h1> Some text... [Correctly formatted hyperlink](https://stackoverflow.com)
1
  • 1
    Alternative tip: No matter whether you're using HTML, Markdown, or both, always add a blank line between formatting elements. This solves parser issues 98% of the time.
    – zcoop98
    Commented Jan 14, 2021 at 15:59

You must log in to answer this question.

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