7

Inequalities where one side is represented as a character or word are stripped as HTML tags if no spaces are included.

For instance:

1 < n < 4 (works fine because of spaces)

1 < this shows up because of the space preceding "this"

The second line does not have a space after the <, so it's treated as an HTML tag, despite the fact that there is no > to close it (see the markdown of this question for a better understanding). Because of that, it's stripped, and inequalities are "invisible." I was editing a question, and this confused me for a while.

I think it's unintentional; it would be better to check for the closing > rather than assume < + a letter is an HTML tag.

0

1 Answer 1

5

I'm going to answer this with basically the same answer I posted on a similar question, modified to this specific instance of course:

To explain it, let's take your second example line: 1 <Hello! Blah blah blah

Now, just that line does not contain any HTML - true. However, it gets inserted into HTML, which could cause some problems. Once run through the Markdown parser and rendered, the full HTML structure ends up looking something like this (again, simplified to make it easier):

<p>1 <Hello! blah blah blah</p>

Now, HTML is not that sophisticated. In the simplest of terms, it's a form of XML, which means anything within angled brackets could potentially be an element when you don't escape it properly. The first <p> is obvious. However, the < sign in the inequality, to any parser in the world, begins a new HTML element. So in reality, the entire <Hello! blah blah blah</p> would get interpreted as a single start tag of a new element. That's certainly not ideal. So, an easy way to fix that is to just remove it. Invalid HTML elements, as well as tags that start but do not ever end, need to be removed so as not to interfere with the other display elements of the post.

This doesn't happen with your first inequality 1 < n < 4 because an HTML element tag cannot have a space between the opening angled bracket < and the name of the tag, e.g. the tag < img> would not be valid. Therefore, that does not get stripped by the Markdown rendered as "invalid HTML" because it is, itself, not valid HTML and therefore we don't need to worry about it.

In other environments where HTML is not allowed at all in the non-rendered version of the post, you could simply run the entire post through an HTML escaping function to replace the < with &lt; and be happy. Unfortunately in an environment which does allow some actual HTML to be used, that's not possible, because then you'd be escaping real HTML elements which are meant to be rendered. It's far easier to just remove random things that shouldn't be used or just utterly don't make sense than to try and look at each HTML tag in a post and determine if it was used properly, if it has an appropriate end tag, etc, etc - HTML parsing is not any fun.


So, if you really want to use an inequality like that in your post, you should explicitly use the HTML entities yourself and not rely on the rendering engine to figure out what you're trying to do for you.

1<n<4

Although, that's much easier to read with the spaces in it anyways.

2
  • I agree that it's easier to read with spaces; inequalities were just an example of this occurrence. Your explanation makes sense. I wonder, though: is there any HTML entity in which two <s before a > is valid? Why not "start over" at each <?
    – Trojan
    Commented Jan 29, 2014 at 19:26
  • 1
    @Trojan I'm not 100% sure as that's not something I've ever tried, but even so, that doesn't mean a browser won't attempt to render it anyways.
    – animuson StaffMod
    Commented Jan 29, 2014 at 19:28

You must log in to answer this question.

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