codeHighlighter 代码高亮控件的使用方法

时间:2021-10-30 00:35:56

1.先下载codeHighlighter

 

2.在程序中添加 ActiproSoftware.CodeHighlighter.Net20.dll   ActiproSoftware.Shared.Net20.dll  CodeHighlighterTest.dll

 

三个dll的引用

 

3.将Languages 和 image 文件夹 拷贝到程序目录中

 

4.在web.config中添加

 

<configuration>
  <configSections>
    <section name="codeHighlighter" type="ActiproSoftware.CodeHighlighter.CodeHighlighterConfigurationSectionHandler, ActiproSoftware.CodeHighlighter.Net20"/>
  </configSections>

 

<codeHighlighter>
    <cache languageTimeout="3"/>
    <keywordLinking enabled="true" target="_blank" defaultKeywordCollectionKey="ActiproKeywords">
      <keywordCollection key="ActiproKeywords">
        <explicitKeyword tokenKey="IdentifierToken" patternValue="Actipro" url="http://www.actiprosoftware.com" caseSensitive="false"/>
        <explicitKeyword tokenKey="IdentifierToken" patternValue="CodeHighlighter" url="http://www.codehighlighter.com" caseSensitive="false"/>
      </keywordCollection>
    </keywordLinking>
    <languages>
      <language key="Assembly" definitionPath="~/Languages/Lexers/ActiproSoftware.Assembly.xml"/>
      <language key="BatchFile" definitionPath="~/Languages/Lexers/ActiproSoftware.BatchFile.xml"/>
      <language key="C#" definitionPath="~/Languages/Lexers/ActiproSoftware.CSharp.xml"/>
      <language key="CSS" definitionPath="~/Languages/Lexers/ActiproSoftware.CSS.xml"/>
      <language key="HTML" definitionPath="~/Languages/Lexers/ActiproSoftware.HTML.xml"/>
      <language key="INIFile" definitionPath="~/Languages/Lexers/ActiproSoftware.INIFile.xml"/>
      <language key="Java" definitionPath="~/Languages/Lexers/ActiproSoftware.Java.xml"/>
      <language key="JScript" definitionPath="~/Languages/Lexers/ActiproSoftware.JScript.xml"/>
      <language key="Lua" definitionPath="~/Languages/Lexers/ActiproSoftware.Lua.xml"/>
      <language key="MSIL" definitionPath="~/Languages/Lexers/ActiproSoftware.MSIL.xml"/>
      <language key="Pascal" definitionPath="~/Languages/Lexers/ActiproSoftware.Pascal.xml"/>
      <language key="Perl" definitionPath="~/Languages/Lexers/ActiproSoftware.Perl.xml"/>
      <language key="PHP" definitionPath="~/Languages/Lexers/ActiproSoftware.PHP.xml"/>
      <language key="PowerShell" definitionPath="~/Languages/Lexers/ActiproSoftware.PowerShell.xml"/>
      <language key="Python" definitionPath="~/Languages/Lexers/ActiproSoftware.Python.xml"/>
      <language key="SQL" definitionPath="~/Languages/Lexers/ActiproSoftware.SQL.xml"/>
      <language key="VB.NET" definitionPath="~/Languages/Lexers/ActiproSoftware.VBDotNet.xml"/>
      <language key="VBScript" definitionPath="~/Languages/Lexers/ActiproSoftware.VBScript.xml"/>
      <language key="XAML" definitionPath="~/Languages/Lexers/ActiproSoftware.XAML.xml"/>
      <language key="XML" definitionPath="~/Languages/Lexers/ActiproSoftware.XML.xml"/>
    </languages>
    <lineNumberMargin foreColor="Teal" paddingCharacter=" " visible="true"/>
    <outlining enabled="true" imagesPath="~/Images/OutliningIndicators/"/>
    <spacesInTabs count="4"/>
  </codeHighlighter>
</configuration>

 

5.在使用页的顶部 注册

增加下面的代码

<%@ Register TagPrefix="CH" Namespace="ActiproSoftware.CodeHighlighter" Assembly="ActiproSoftware.CodeHighlighter.Net20" %>

 

6.添加控件

      <pre >
                <CH:CodeHighlighter runat="server" OutliningEnabled="true" ID="CssCodeHighlighter"
                    LineNumberMarginVisible="true">
                </CH:CodeHighlighter></pre>

 

7.控件赋值

 

  this.CssCodeHighlighter.LanguageKey = ds.Tables[0].Rows[0]["codetype"].ToString().Trim();
  this.CssCodeHighlighter.Text = ds.Tables[0].Rows[0]["Code"].ToString().Trim();