Sense/Net SourceCode Field Control
This is a Field Control for Sense/Net ECMS, it provides syntax highlighting.
- Download and unzip the binary package to your Sense/Net bin folder.
- Move the SyntaxHighlighter folder into the JS folder.
- in the Web.config file: in the configuration -> system.web -> pages -> controls add the following line:
<add tagPrefix="sn" namespace="SourceCode" assembly="SourceCode" />
- Now you can add to your Browse ContentView file the SourceCode Control:
<sn:SourceCode ID="MyCode" runat="server" Language="CSharp" FieldName="MyCode" />
As you can see, you can select the language to highlight with Language attribute. Clck here to see all available languages: Available Languages
The field control was made to be able to use any syntax highlighter engine. By default there are 2 engines to select from:
- ColorCode - Syntax Highlighting/Colorization for .NET
You have 2 different options to switch between the engines:
- You can set a global configuration to for all SourceCode Field Controls:
add to the configuration -> appSettings section in your Web.config file the following line:
<!-- SourceCode Field Control Configuration -->
<add key="Highlighter" value="SourceCode.ColorCodeHighlighter" />
- Or you can set for only one Filed Control by setting the Highlighter attribute:
<sn:SourceCode ID="MyCode" runat="server" Highlighter="SourceCode.SyntaxHighlighter" Language="CSharp" FieldName="MyCode" />
The highlighter is actually the FullName of the class witch will be instanced to format our text.
And now we are getting to the point: If you don't like the highlighter engines included in the FieldControl, you can simply add your own!
Let's see how can be this done:
- Create a new class library
- Add reference to SourceCode.dll assembly
- implement SourceCode.IHighlighter interface
- override the Highlight function:
- this function recieves a string, and returns it highlighted
- Build your application to the sensenet bin folder
And it's done! So simple :) Now you can add your hightligter class with the following format: <Namespace>.<Classname>,<Assembly>
This part is importent! If you miss the namespace or the assembly it won't work!
Let's see the example below:
public class MyHighlighter : IHighlighter
#region IHighlighter Members
public string Highlight(string textToHightlight, string Language, Page page)
If your assembly called MyHighlighter.dll, than you have to add the following Highlighter attribute:MyHighlighterNameSpace.MyHighlighter,MyHighlighter
Have a good time! :)