为什么我的<pre> and <code> tags reading the markup instead of producing code snipets?</code></pre>

时间:2010-01-25 18:52:09

标签: html markup code-snippets

我正在为希望协助我的组织(CURE国际)协助海地地震救灾工作的教会的资源页面工作:http://blog.helpcurenow.org/test/mockups/jan2010/jan2010_haiti_church_resources.html

我遇到的麻烦是,在第4步,您会看到我创建了横幅广告,并且我正在尝试为用户复制并粘贴到他们的博客/网站中生成代码snipets(也就是代码块) /不管。

我使用了“pre”和“code”标签,但浏览器仍在呈现HTML而不是将标记显示为文本。

有人可以帮我解释为什么我会得到这个结果吗?

以下是标记示例:

<li class="haitiWebBanner">
<p class="webBannerSize">300 x 250</p>
<a href="http://helpcurenow.org/haitirelief"><img src="http://static.helpcurenow.org/images/campaigns/jan2010/haiticrisis/cure-haiti-banner-300x250.jpg" title="Click Here to Donate Now!" alt="Help save lives in Haiti by supporting the relief effort through CURE International" width="300" height="250" border="0" /></a>

<pre><code class="html"><a href="http://helpcurenow.org/haitirelief"><img src="http://static.helpcurenow.org/images/campaigns/jan2010/haiticrisis/cure-haiti-banner-300x250.jpg" title="Click Here to Donate Now!" alt="Help save lives in Haiti by supporting the relief effort through CURE International" width="300" height="250" border="0" /></a></code></pre>

5 个答案:

答案 0 :(得分:5)

“代码”表示“这是标记的代码”

“Pre”表示“此数据已预先格式化”(就空白而言)

它们都不是“不应将此数据视为HTML”

&表示为&amp;,将<表示为&lt;,将>表示为&gt;

答案 1 :(得分:3)

您仍然需要考虑特殊字符&amp; lt;和&amp; gt;

<pre><code class="html">&gt;a href=......... &lt;

答案 2 :(得分:2)

&lt; pre&gt;&lt; / pre&gt;标记对不会改变浏览器解析它们中的内容的方式(即,浏览器需要解析的带有标记的HTML)。相反,它只是告诉浏览器该对内的内容是未格式化的,应该像这样呈现给用户。

您需要做的是转义HTML(即“&lt;”到“&amp; lt;”等),以便浏览器知道它应该显示原始字符。

答案 3 :(得分:1)

对于&lt; pre&gt;内的代码标签,进行全局搜索并替换“&lt;”用“&amp; lt;”。

答案 4 :(得分:1)

那是因为代码和预标签不能以这种方式工作。改变你的'&lt;'到'&amp; lt;'和'&gt;'到'&amp; gt;'它也可以按你的意愿工作。