简体   繁体   English

“ google-code-prettify”网页中的代码段语法高亮显示不起作用

[英]Syntax highlighting of code snippets in a web page “google-code-prettify” not working

I have following code, 我有以下代码,

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link href="../../../Styles/prettify.css" rel="stylesheet" type="text/css" />
    <script src="../../../Scripts/prettify.js" type="text/javascript"></script>
</head>
<body>

<p>And from code behind write following :</p>

<pre class="prettyprint">
    protected void Page_Load(object sender, EventArgs e)
        {
            lblLoading.Text = "Loading News...";
        }
</pre>
</body>
</html>

I am not able to see code syntax at the result. 我看不到结果的代码语法。 What have I missed? 我错过了什么?

The result is like this: 结果是这样的:

An online demo is here: http://jsfiddle.net/yKss3/ 在线演示在这里: http : //jsfiddle.net/yKss3/

Change 更改

<body>

to

<body onload="prettyPrint()">

Prettify's README file says: Prettify的README文件显示

  1. Download a distribution 下载发行版
  2. Include the script and stylesheets in your document (you will need to make sure the css and js file are on your server, and adjust the paths in the script and link tag) <link href="prettify.css" type="text/css" rel="stylesheet" /> <script type="text/javascript" src="prettify.js"></script> 在文档中包含脚本和样式表(您需要确保服务器上包含css和js文件,并在脚本和链接标记中调整路径) <link href="prettify.css" type="text/css" rel="stylesheet" /> <script type="text/javascript" src="prettify.js"></script>
  3. Add onload="prettyPrint()" to your document's body tag. onload="prettyPrint()"到文档的body标签中。
  4. Modify the stylesheet to get the coloring you prefer 修改样式表以获取您喜欢的颜色

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM