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](https://commonmark.org/).

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

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)

### 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](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)

### 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)
```