There are two main options available for highlighting text on a web site. The first is to have the server perform the highlighting by using some or other external library, and the second option is to use client side highlighting via a Javascript app.
We chose server side for a variety of reasons. Firstly we wanted to demonstrate tinyMCE integration, and server side processing provides us with an ideal opportunity to do so. Secondly, the overheads involved in client side highlighters may not be worth it, and Third we really liked the approach of the Pygments highlighter which is also Python and has a really snug fit with what we wanted.
Many wiki type sites or documentation sites use some form of markdown, for example Wikipedia's WikiEditor to produce HTML documents. While these work quite well, we think the WYSIWYG approach of tinyMCE is really elegant and lowers the barrier to entry for producing HTML really fast.
There are numerous other popular visual editors available which we might have used, such as the CKEditor (formarly FCKEditor) or Wikipedia's new visual editor which is to replace WikiEditor. TinyMCE is simple to integrate and does the job.
Looking at attachments.Source()
implementation, the highlighter is called in the following method:
Clearly, the variable pygments
is being set to the utility exporting an ISourceHighlight
interface with the name 'Pygments'. The utility is then called with the text and the required format specifier.
The idea behind utilities, is that we can rather easily add alternative highlighters with the same interface by merely changing the name. This provides Grok with an astonishing amount of pluggability.
The utility we find is defined in the colourise.py source file as follows:
Another global utility defines the list of available syntax highlighter formats as a vocabulary. Vocabularies are rather powerful constructs which are well worth the effort spent learning about them.
The above vocabulary is specified as a source in the 'fmt' attribute for the IAttachment
interface schema class.