4

In the question Can the COVID-19 genome really fit into a social media post (XKCD 2299), is this ever done in practice? I had a typo which caused the link not to show:

X<CD 2299 [Coronavirus Genome 2](https://xkcd.com/2299/) says:

shows as

XCoronavirus Genome 2 says:

Once I fixed the faux K "<" to a real K, the display of the link returns.

XKCD 2299 Coronavirus Genome 2 says:

Why does the single instance of "<" without a complementary ">" do this?

3

1 Answer 1

14

That is because the less than symbol followed by a character is interpreted as the opening bracket of an HTML tag. It is later closed by the ending of the anchor tag that the Markdown parser inserts in place of your link markup.

Basically, the HTML looks like this:

X<CD <a href="https://xkcd.com/2299/">Coronavirus Genome 2</a>

The text <CD <a href="https://xkcd.com/2299/"> is treated as an HTML element, and since cd is not one of the allowed HTML elements, that entire part is stripped out, resulting in:

XCoronavirus Genome 2</a>

The link isn't created because of the malformed opening tag.

If you want to ensure that the opening angle bracket will display as text rather than possibly interfering with the page rendering, properly encode it as &lt; (and &gt; for the closing bracket).

5
  • Okay I'm getting there... can you clarify what the "anchor tag that the Markdown parser inserts in place of your link markup" is? Is it one of the close square brackets or parentheses?
    – uhoh
    Commented Apr 28, 2020 at 1:13
  • 2
    Sorry answering from my phone. Hope this makes sense Commented Apr 28, 2020 at 1:17
  • oic the html in the web page that my browser interprets, not in my typed post, got it.
    – uhoh
    Commented Apr 28, 2020 at 1:21
  • 3
    You should also mention that SE strips from the HTML which is generated from the Markdown all but a limited number of specific HTML tags (also with limited specific attributes). In this case the <CD …> would have been removed and not included in the HTML.
    – Makyen
    Commented Apr 28, 2020 at 1:23
  • 2
    @Makyen Feel free to edit that in. It's a lot to type on the phone. Commented Apr 28, 2020 at 1:24

You must log in to answer this question.

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