Thomas announced version 2.0 of his code highlighter. I have not given it a full try yet, but I thought it might be nice to point out how easy it should be to implement this in the next (0.96) version of .Text.
0.96 has a pretty simple EntryHandling system, which basically allows you to execute code before of after an Entry updated. (Posts, Articles, Comments, and Trackbacks are all entries).
The interface is still not “locked”, but for now it looks like this:
public interface IEntryFactoryHandler
{
void Process(Entry e);
void Configure();
}
In the web.config, you can configure:
- The type of entires which use this handler
- Whether the handler is valid for new or existing items (ProcessAction)
- If the handler should process before or after connecting to the datastore (ProcessState)
- If the handler should process synchronous or asynchronous
You should note:
- If ProcessState = ProcessState.PreCommit, the Handler must be processed Synchronously
- Configure will always be fired on the main thread, so any items you might need to complete Process should be set and/or referenced here.
- Multiple ProcessAction's can be configured, but only one ProcessState can be set.
With that out of the way, we can do a quick example:
using Dottext.Framework.Components;
using Dottext.Framework.EntryHandling
using AylarSolutions.Highlight;
using AylarSolutions.Highlight.Extensions;
namespace CC
{
public class ColorCoderEntryFactoryHandler : IEntryFactoryHandler
{
public void Process(Entry e)
{
CodeBlockHighlighter highlighter = new CodeBlockHighlighter();
highlighter.InputIsHtmlEncoded = true;
e.Body = highlighter.Highlight(e.Body);
}
public void Configure(){}
}
}
Read: Color Coding with EntryHandlers