代码之家  ›  专栏  ›  技术社区  ›  Lone Learner

什么样的文本可以包装在HTML代码标记中?

  •  2
  • Lone Learner  · 技术社区  · 6 年前

    我想知道什么样的文本属于HTML <code>

    例如,我知道这是一个很好的HTML用法 < 标签:

    Use the <code>str()</code> function to convert the object into a string.
    

    但我不确定这些是否是 < 标签:

    1. The list of users can be found at <code>/etc/passwd</code>.
    2. We need to wait for <code>200 OK</code> response before the next step.
    3. Enter the <code>ls</code> command to obtain a directory listing.
    4. Compile the source code in <code>foo.c</code> to <code>foo.o</code>.
    

    <代码>

    2 回复  |  直到 6 年前
        1
  •  1
  •   unor Daniel Garijo    6 年前

    的定义 code element

    代码 元素表示计算机代码的片段。它可以是XML元素名、文件名、计算机程序或计算机可以识别的任何其他字符串。

    这就是决定是否允许(即语义)使用元素的原因。但您还应该检查是否有更具体的元素可用。

    回顾你的例子

    Use the <code>str()</code> function to convert the object into a string.
    

    这很好。

    The list of users can be found at <code>/etc/passwd</code>.
    

    这很好。

    We need to wait for <code>200 OK</code> response before the next step.
    

    你可以考虑使用 samp element 相反,它表示“来自另一个程序或计算系统的样本或引用的输出”。

    Enter the <code>ls</code> command to obtain a directory listing.
    

    你可以考虑使用 kbd element 相反,它表示“用户输入(通常是键盘输入,[])”。

    Compile the source code in <code>foo.c</code> to <code>foo.o</code>.
    

    这很好。

        2
  •  0
  •   tao    6 年前

    <code> 标签。

    <代码>

    任何 phrasing content 有效的 HTML spec's


    代码标记类似于 <pre>

    很多时候,当代码片段、函数或方法名(特定于编程)用于其他内容时,它们的标记(和格式)与普通文本不同是很重要的(或者至少是需要的)。
    这就是预期的目的 <代码> 标记已添加到HTML。

    这并不意味着有任何机制阻止你将它用于你认为合适的任何其他目的,只要它适合这个目的,考虑到它只包含短语内容的局限性。