2

If I want to write something like "low < high" in a <pre> or <pre><code> tag, the rendering shows only "low", plus some wrong new line afterwards:


# here we are in a pre/code tag
low 

But it works within back-ticks and with 4 spaces indentation low < high # here are backticks

low < hight  # here is indented

However "high > low" renders without problems, although the bug above keeps adding spurious new lines.


# here we are in a pre/code tag
hight > low

high > low # here are backticks

hight > low  # here is indented

I'm using version 49.0.2623.108 Ubuntu 15.10 (64-bit)

1

2 Answers 2

7

Since everything in a pre is HTML, you have to properly escape the <, else it thinks it is the start of a HTML tag.

This gives the desired result:

<pre><code>
# here we are in a pre/code tag
low &lt; high
</code></pre>

Result:


# here we are in a pre/code tag
low < high

Related feature request to change this behavior (the propsal in the feature request goes against the HTML standards, where I have to agree with Shog9): Can we have the pre tag work as the code tag does for angle brackets?

1
  • I see. I guess it makes sense. About the request in the link: I agree that no one should change HTML standards. However, would be possible to warn the user that there are un-matched tags or </> within <pre><code>? Commented Apr 22, 2016 at 9:28
3

I tend to think that is and not a bug. How do you think the parser should distinguish between <pre>foo <code>, where you want the second < to be interpreted as start of an HTML tag, and <pre>low < high, where you want the second < to be escaped to &lt;?

When using HTML directly, you are in advanced territory; you are expected to do your escapes yourself as needed.

You must log in to answer this question.

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