Template:Code-span

{{{1}}}

文档图示 模板文档[查看] [编辑] [历史] [清除缓存]

模板介紹 编辑

本模板用于修饰代码,可以强制用等宽字体显示作为代码显示的文字,并配上灰色底色。

规范使用建议 编辑

如果你喜欢 HTML 标记或者希望做正确的事,建议使用以下方式替代本模板显示程序代码的用途:

  • 行内等宽代码:{{#tag:code|你好世界|lang=zh}}<code lang="zh">你好世界</code>你好世界
    • #tag 中 lang 可以换成 |style= 之类的其他属性。
  • 行内高亮代码{{#tag:syntaxhighlight|console.log(`JS running on ${window.href}.`)|lang=js|inline=}}<syntaxhighlight lang="js" inline>console.log(`JS running on ${window.href}.`)</syntaxhighlight>console.log(`JS running on ${window.href}.`)
    • syntaxhighlight 可以用 source 代替
    • 去掉 inline 可以获得类似 pre 的代码块

使用方法 编辑

{{codespan|代码}}

範例 编辑

输入

  • {{codespan|Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405}}

可得到

  • Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405