I'm using <code>
tag inside of a <pre>
tag to show code on my blogger blog. Unfortunately it doesn't work with HTML tags. Is there any way to show "<div>
" inside of <pre>
or <code>
tag without actually interpreting it as HTML? This is what I do right now:
我使用标签内的
标签来显示我博客上的代码。不幸的是,它不能使用HTML标签。有没有办法在或 tag中显示"
"而不将其解释为HTML?这就是我现在所做的:
<pre>
<code>
.class {
color:red;
}
// I would like HTML code inside this
</code>
</pre>
Which works ok for everything except HTML. Any idea how to achieve this? Thanks.
除了HTML,其他都可以。你知道怎么做吗?谢谢。
7 个解决方案
#1
60
Unfortunately it doesn't work with HTML tags.
不幸的是,它不能使用HTML标记。
<code>
means "This is code", <pre>
means "White space in this markup is significant". Neither means "The content of this element should not be treated as HTML", so both work perfectly, even if they don't mean what you want them to mean.
表示“这是代码”,
表示“这个标记中的空格是重要的”。两者都不意味着“不应该将该元素的内容视为HTML”,因此两者都可以很好地工作,即使它们并不意味着您想要它们的意思。
Is there any way to show "
<div>
" inside of<pre>
or<code>
tag without actually interpreting it as HTML?有没有办法在
或tag中显示"
"而不将其解释为HTML?
If you want to render a <
character then use <
, with >
for >
and &
for &
.
如果你想渲染一个 <字符,然后使用<> ,,&。
You can't (in modern HTML) write markup and have it be interpreted as text.
您不能(在现代HTML中)编写标记并将其解释为文本。
#2
31
It seems like a readonly textarea does pretty much what you want.
看起来readonly textarea几乎可以满足您的需求。
<textarea readonly> <!-- html code --> </textarea>
#3
12
You can use the "xmp" element. The <xmp></xmp>
has been in HTML since the beginning and is supported by all browsers. Even it should not be used, it is broadly supported.
您可以使用“xmp”元素。
Everything inside <xmp></xmp>
is taken as it is (no markup lke tags or character references is recognized there) except, for apparent reason, the end tag of the element itself.
Otherwise "xmp" is rendered like "pre".
否则,“xmp”将呈现为“pre”。
#4
7
Try:
试一试:
<xmp></xmp>
for exemple:
为例:
<pre>
<xmp><!-- your html code --></xmp>
</pre>
bye
再见
#5
2
Just escape the HTML tags. For example -
只是转义HTML标签。例如,
Replace < with <
替换< & lt;
Replace > with >
>替换为在
Complete lookup here
完成在这里查找
#6
0
Try CodeMirror (https://codemirror.net/)
尝试CodeMirror(https://codemirror.net/)
It's a lightweight library that styles code in HTML. Here's a screenshot of what I'm referring to:
它是一个用HTML样式化代码的轻量级库。这是我所指的截屏:
Worked well for us!
工作对我们好!
#7
-3
Yes, with an escape xml function. You'll need to have jQuery enabled for it to work though.
是的,带有转义xml函数。但是,您需要启用jQuery才能工作。
<pre>
${fn:escapeXml('
<!-- all your code -->
')};
</pre>
#1
60
Unfortunately it doesn't work with HTML tags.
不幸的是,它不能使用HTML标记。
<code>
means "This is code", <pre>
means "White space in this markup is significant". Neither means "The content of this element should not be treated as HTML", so both work perfectly, even if they don't mean what you want them to mean.
表示“这是代码”,
表示“这个标记中的空格是重要的”。两者都不意味着“不应该将该元素的内容视为HTML”,因此两者都可以很好地工作,即使它们并不意味着您想要它们的意思。
Is there any way to show "
<div>
" inside of<pre>
or<code>
tag without actually interpreting it as HTML?有没有办法在
或tag中显示"
"而不将其解释为HTML?
If you want to render a <
character then use <
, with >
for >
and &
for &
.
如果你想渲染一个 <字符,然后使用<> ,,&。
You can't (in modern HTML) write markup and have it be interpreted as text.
您不能(在现代HTML中)编写标记并将其解释为文本。
#2
31
It seems like a readonly textarea does pretty much what you want.
看起来readonly textarea几乎可以满足您的需求。
<textarea readonly> <!-- html code --> </textarea>
#3
12
You can use the "xmp" element. The <xmp></xmp>
has been in HTML since the beginning and is supported by all browsers. Even it should not be used, it is broadly supported.
您可以使用“xmp”元素。
Everything inside <xmp></xmp>
is taken as it is (no markup lke tags or character references is recognized there) except, for apparent reason, the end tag of the element itself.
Otherwise "xmp" is rendered like "pre".
否则,“xmp”将呈现为“pre”。
#4
7
Try:
试一试:
<xmp></xmp>
for exemple:
为例:
<pre>
<xmp><!-- your html code --></xmp>
</pre>
bye
再见
#5
2
Just escape the HTML tags. For example -
只是转义HTML标签。例如,
Replace < with <
替换< & lt;
Replace > with >
>替换为在
Complete lookup here
完成在这里查找
#6
0
Try CodeMirror (https://codemirror.net/)
尝试CodeMirror(https://codemirror.net/)
It's a lightweight library that styles code in HTML. Here's a screenshot of what I'm referring to:
它是一个用HTML样式化代码的轻量级库。这是我所指的截屏:
Worked well for us!
工作对我们好!
#7
-3
Yes, with an escape xml function. You'll need to have jQuery enabled for it to work though.
是的,带有转义xml函数。但是,您需要启用jQuery才能工作。
<pre>
${fn:escapeXml('
<!-- all your code -->
')};
</pre>