Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to escape < and > inside <pre> tags

I'm trying to write a blog post which includes a code segment inside a <pre> tag. The code segment includes a generic type and uses <> to define that type. This is what the segment looks like:

<pre>
    PrimeCalc calc = new PrimeCalc();
    Func<int, int> del = calc.GetNextPrime;
</pre>

The resulting HTML removes the <> and ends up like this:

PrimeCalc calc = new PrimeCalc();
Func del = calc.GetNextPrime;

How do I escape the <> so they show up in the HTML?

like image 691
urini Avatar asked Sep 03 '08 17:09

urini


People also ask

How do you escape tags?

Escape characters will always begin with the ampersand symbol (&) and end with a semicolon symbol (;). The characters in between the ampersand and semicolon make up the specific code name or number for a particular character.

What is an alternative of pre tag?

The fonts included in that rule make each character the same width which is common formatting for text in a <pre> tag. Or, better yet, use the <code> tag if it isn't stripped out by your CMS. It acts like the <pre> tag but is semantically correct for displaying code. +1 for mentioning <code> and semantics.

How do I hide a pre tag in HTML?

You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid. A hidden <pre> element is not visible, but it maintains its position on the page. Removing the hidden attribute makes it re-appear.


2 Answers

<pre>
    PrimeCalc calc = new PrimeCalc();
    Func&lt;int, int&gt; del = calc.GetNextPrime;
</pre>
like image 84
John Sheehan Avatar answered Nov 02 '22 00:11

John Sheehan


<pre>&gt;</pre>

renders as:

>

So you want:

<pre>
    PrimeCalc calc = new PrimeCalc();
    Func&lt;int, int&gt; del = calc.GetNextPrime;
</pre>

which turns out like:

    PrimeCalc calc = new PrimeCalc();
    Func<int, int> del = calc.GetNextPrime;
like image 34
Chris Marasti-Georg Avatar answered Nov 02 '22 01:11

Chris Marasti-Georg