如何在标签中转义

时间:2021-09-06 06:56:32

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:

生成的HTML删除<>,结果如下:

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

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

如何转义<>,使它们出现在HTML中?

8 个解决方案

#1


84  

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

#2


16  

<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;

#3


10  

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

使用& lt;和比;在html中执行 <和> 。

#4


5  

&lt; and &gt; respectively

& lt;和比;分别

#5


4  

How about:

如何:

&lt; and &gt;

Hope this helps?

希望这可以帮助?

#6


2  

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

正如rp所言,只需将大于(>)和小于(<)符号替换为它们的html实体等价。这里有一个例子:

<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;

#7


-1  

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;

它可能是您的博客软件的特定内容,但是您可能想尝试以下字符串(删除下划线字符):&_lt;&_gt;

#8


-3  

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.

你需要启用jQuery才能工作,tho。

#1


84  

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

#2


16  

<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;

#3


10  

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

使用& lt;和比;在html中执行 <和> 。

#4


5  

&lt; and &gt; respectively

& lt;和比;分别

#5


4  

How about:

如何:

&lt; and &gt;

Hope this helps?

希望这可以帮助?

#6


2  

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

正如rp所言,只需将大于(>)和小于(<)符号替换为它们的html实体等价。这里有一个例子:

<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;

#7


-1  

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;

它可能是您的博客软件的特定内容,但是您可能想尝试以下字符串(删除下划线字符):&_lt;&_gt;

#8


-3  

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.

你需要启用jQuery才能工作,tho。