How to escape < and > inside <pre> tags

跟風遠走 提交于 2019-11-26 18:46:52
<pre>
    PrimeCalc calc = new PrimeCalc();
    Func&lt;int, int&gt; del = calc.GetNextPrime;
</pre>
Chris Marasti-Georg
<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;
crashmstr

Use &lt; and &gt; to do < and > inside html.

ckpwong

&lt; and &gt; respectively

How about:

&lt; and &gt;

Hope this helps?

akdom

What rp said, just replace the greater-than(>) and less-than(<) symbols with their html entity equivalent. Here's an example:

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

This should appear as (this time using exactly the same without the prepended spaces for markdown):

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

It's probably something specific to your blog software, but you might want to give the following strings a try (remove the underscore character): &_lt; &_gt;

A better way to do is not to have to worry about the character codes at all. Just wrap all your code inside the <pre> tags with the following

<pre>
${fn:escapeXml('
  <!-- all your code -->
')};
</pre>

You'll need to have jQuery enabled for it to work, tho.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!