在网页中加高亮显示源代码的工具

刚刚发现一个老外用Javascrīpt编写的好东西:dp.SyntaxHighlighter。它可以在网页中对各种程序源代码
语法进行加亮显示。支持当前流行的各种编程语言:C#、CSS
、C++、Delphi、Java
、Javascrīpt、PHP
、Python、Ruby、SQL、 Visual Basic、XML
/ HTML

  下载地址:http://www.dreamprojections.com/syntaxhighlighter/

  演示地址:http://www.dreamprojections.com/syntaxhighlighter/Tests/PHP.html

下载
1

下载
2

  使用方法:
  1、假设网页文件test.htm存放在一个目录,则将dp.SyntaxHighlighter解压缩到该目录下的子目录,假设为images
  2、在网页的<head></head>之间插入以下代码:

 

 
  1. <link type=
    "text/css"
     rel=
    "stylesheet"
     href=
    "images/Styles/SyntaxHighlighter.css"
    ></link>  


      3、在网页要显示程序源代码的地方插入以下代码(其中的class="js"表示以js语法显示源代码,其他可设定的class值分别为c#、css、c、delphi、java、js、php、python、ruby、sql、vb、xml):
  1. <textarea name=
    "code"
     
    class
    =
    "js"
     rows=
    "15"
     cols=
    "100"
    >  
  2. 程序源代码放在这儿  
  3. </textarea>  



  4、在网页尾部的</body>之前插入以下代码:

  1. <scrīpt 
    class
    =
    "javascrīpt"
     src=
    "images/scrīpts/shCore.js"
    ></scrīpt>  
  2. <scrīpt class
    =
    "javascrīpt"
     src=
    "images/scrīpts/shBrushCSharp.js"
    ></scrīpt>  
  3. <scrīpt class
    =
    "javascrīpt"
     src=
    "images/scrīpts/shBrushPhp.js"
    ></scrīpt>  
  4. <scrīpt class
    =
    "javascrīpt"
     src=
    "images/scrīpts/shBrushJscrīpt.js"
    ></scrīpt>  
  5. <scrīpt class
    =
    "javascrīpt"
     src=
    "images/scrīpts/shBrushJava.js"
    ></scrīpt>  
  6. <scrīpt class
    =
    "javascrīpt"
     src=
    "images/scrīpts/shBrushVb.js"
    ></scrīpt>  
  7. <scrīpt class
    =
    "javascrīpt"
     src=
    "images/scrīpts/shBrushSql.js"
    ></scrīpt>  
  8. <scrīpt class
    =
    "javascrīpt"
     src=
    "images/scrīpts/shBrushXml.js"
    ></scrīpt>  
  9. <scrīpt class
    =
    "javascrīpt"
     src=
    "images/scrīpts/shBrushDelphi.js"
    ></scrīpt>  
  10. <scrīpt class
    =
    "javascrīpt"
     src=
    "images/scrīpts/shBrushPython.js"
    ></scrīpt>  
  11. <scrīpt class
    =
    "javascrīpt"
     src=
    "images/scrīpts/shBrushRuby.js"
    ></scrīpt>  
  12. <scrīpt class
    =
    "javascrīpt"
     src=
    "images/scrīpts/shBrushCss.js"
    ></scrīpt>  
  13. <scrīpt class
    =
    "javascrīpt"
     src=
    "images/scrīpts/shBrushCpp.js"
    ></scrīpt>  
  14. <scrīpt class
    =
    "javascrīpt"
    >  
  15. dp.SyntaxHighlighter.HighlightAll('code'
    );  
  16. </scrīpt> 
此条目发表在article分类目录,贴了标签。将固定链接加入收藏夹。