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?
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.
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.
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.
<pre>
PrimeCalc calc = new PrimeCalc();
Func<int, int> del = calc.GetNextPrime;
</pre>
<pre>></pre>
renders as:
>
So you want:
<pre>
PrimeCalc calc = new PrimeCalc();
Func<int, int> del = calc.GetNextPrime;
</pre>
which turns out like:
PrimeCalc calc = new PrimeCalc(); Func<int, int> del = calc.GetNextPrime;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With