导航:[首页]->[www]->[google-code-prettify简介]

##官方网站:google-code-prettify使用说明 ##详细说明

  • 加载对应的js和css,例如
  • 将代码放置在一个pre结构中 <pre class="prettyprint">您的代码</pre>
  • google-code-prettify可以自动判断语言,不过你可以手动指定语言 <pre class="prettyprint lang-html"> The lang-* class specifies the language file extensions. File extensions supported by default include “bsh”, “c”, “cc”, “cpp”, “cs”, “csh”, “cyc”, “cv”, “htm”, “html”, “java”, “js”, “m”, “mxml”, “perl”, “pl”, “pm”, “py”, “rb”, “sh”, “xhtml”, “xml”, “xsl”. </pre>
  • 为了开启行号,可以用如下的方式 <pre class="prettyprint linenums:4">// This is line 4. foo(); bar(); baz(); boo(); far(); faz(); <pre>
  • 为了设定代码高亮的风格,可以修改prettify的css,具体参考这里
  • 为了方便,我将这些内容放到post.html里面 <head>

              // 导入Prettify的javascript
              prettyPrint()
          })
          </script>
      </head>