【问题标题】:How to render tags as html in browser如何在浏览器中将标签呈现为 html
【发布时间】:2012-05-01 17:44:29
【问题描述】:

如何在浏览器中将这些标签呈现为 html,例如铬?

<testname=tar_tests.sh>
    <description>
        Test basic functionality of `tar` command.
    <\description>
    <test_location>
        ltp/testcases/commands/tar/tar_tests.sh
    <\test_location>
<\testname>

<testname=unzip>
    <description>
        Test basic functionality of `unzip` command.

    <\description>
    <test_location>
        ltp/testcases/commands/unzip
    <\test_location>
<\testname>

输出:

<testname=tar_tests.sh> <description> Test basic functionality of `tar` command. <\description> <test_location> ltp/testcases/commands/tar/tar_tests.sh <\test_location> <\testname> <testname=unzip> <description> Test basic functionality of `unzip` command. <\description> <test_location> ltp/testcases/commands/unzip <\test_location> <\testname>

【问题讨论】:

标签: html tags rendering


【解决方案1】:

您需要为括号使用 HTML 实体。将&amp;lt; 更改为&amp;lt; 并将&amp;gt; 更改为&amp;gt;

【讨论】:

  • 看起来仍然很丑陋且难以阅读。我在上面添加了输出。我怎样才能让它看起来漂亮和可读?
【解决方案2】:

您需要将&amp;lt;&amp;gt; 字符分别转义为&amp;lt;&amp;gt;

所以,在你的 HTML 中,为了显示:

<testname=tar_tests.sh>

你应该写:

&lt;testname=tar_tests.sh&gt;

【讨论】:

    【解决方案3】:

    如果您将文本包装在&lt;pre&gt;...&lt;/pre&gt; 中,它将被格式化,您无需将所有标签更改为 HTML 实体。保留空白和布局。

    <pre>
    &lt;testname=tar_tests.sh>
    ...
    </pre>
    

    【讨论】:

    • @MrLister:现在我已经更新了答案。 &lt;pre&gt; 是保留布局的正确方法。如果您不想更改 &gt; 字符,则无需需要(尽管这样做可能是最安全的)。
    猜你喜欢
    • 1970-01-01
    • 2014-05-17
    • 2018-09-04
    • 2016-01-14
    • 1970-01-01
    • 2018-01-01
    • 2015-05-01
    • 1970-01-01
    • 2019-09-21
    相关资源
    最近更新 更多