2011-03-24 72 views
0

我在我的asp.net应用程序中使用JQuery语法高亮显示。JQuery语法高亮片段

http://www.steamdev.com/snippet/

我已经包含了脚本和CSS文件在使用一节中提到。

而且下面的代码:

<script> 
$(document).ready(function(){ $("pre.htmlCode").snippet("html"); 
    // Finds <pre> elements with the class "htmlCode"  
    // and snippet highlights the HTML code within. 
     $("pre.styles").snippet("css",{style:"greenlcd"}); 
      // Finds <pre> elements with the class "styles" 
       // and snippet highlights the CSS code within 
        // using the "greenlcd" styling. 
     $("pre.js").snippet("javascript",{style:"random",transparent:true,showNum:false});  
     // Finds <pre> elements with the class "js"  
     // and snippet highlights the JAVASCRIPT code within  
     // using a random style from the selection of 39  
     // with a transparent background  
     // without showing line numbers. 
    }); 

</script> 
<script> 
$(document).ready(function(){ 
     $("pre#dynamic").snippet("php",{style:"navy",clipboard:"js/ZeroClipboard.swf",showNum:false}); 
       // Highlights a snippet of PHP code with the "navy" style   
       // Hides line numbers  
       $("pre#dynamic").click(function(){ 
         $(this).snippet({style:"vampire",transparent:true,showNum:true});  
          // Changes existing snippet's style to "vampire"   
          // Changes the background to transparent   
          // Shows line numbers 
    }); 



    }); 



</script> 

结果:我得到的代码段像下面

Code highlighting

但代码是从荧光笔走出去,我也没有别的选择复制剪贴板。

如何将其添加到我的页面?

插入数据时,我只使用<pre></pre>标签。我需要在预先指定语言吗?因为我还没有得到的颜色代码

编辑

我打电话下面

<link href="jquery.snippet.css" rel="stylesheet" type="text/css" /> 
<script type="text/javascript" src="<%=ResolveUrl("~/JS/jquery.snippet.js")%>" ></script> 

EDIT1

正是在降级模式一样的JS和CSS文件当我点击“文本”链接时,我可以看到所有的格式都消失了。任何建议如何保持扩展格式的HTML模式?

enter image description here

回答

0

我想你可能必须指定在类的pre元素的语言,例如:

<pre class="htmlCode"> 
    //...code snippet here 
</pre> 

代码您发布以下外观:

<pre class="htmlCode">...</pre> <!-- html --> 
<pre class="styles">...</pre> <!-- css --> 
<pre class="js">...</pre> <!-- javascript --> 
<pre id="dynamic">...</pre> <!-- php --> 

编辑

要添加C#中,你可能需要做的:

<pre class="csharp"> 
    public static void Main(string[] args) 
    { 
     Console.WriteLine("Hello World"); 
     Console.ReadLine(); 
    } 
</pre> 
<script> 
    $("pre.csharp").snippet("csharp"); 
</script> 

注意它更容易使用csharp的,而不是C#作为语言的名称,如#有在网络上一个特殊的意义。

+0

@大卫肯普我试过相同的我保持像

 // Code
但结果是一样的。我错过了什么吗? – Chris 2011-03-24 13:44:44

+0

@Chris - 我已经为你修改了我的答案 – 2011-03-24 13:50:05

+0

@David Kemp感谢David,现在工作正常。但我有另一个问题,请检查编辑1部分。 – Chris 2011-03-24 14:16:39