RSS Feed

ScrewTurn Syntax Highlighter

December 6, 2008 16 Comments »

Overview

This is a lightweight Syntax Highlighter plugin for ScrewTurn Wiki. The plugin uses the Lonwas Highlighter, by Thomas Johansen and Christian Nordbakk, which currently supports 23 languages by default and is extensible through the use of an XML file.

Note: The Syntax Highlighter is only being used as a lightweight highlighter. This means that is does not support of the more advanced features, such as line numbering or keyword hyperlinks.

Usage

To highlight code simply surround the desired code with <code language> and </code>, where “language” denotes the language of the code E.G. C#.

Example:<code c#>public static void TestMethod() { return; }</code>

The <code> tags are parsed during phase1 (prior to the wiki parsing). During this time — apart from the syntax highlighting — the <code> tag is replaced with <pre class=“code language”>, where language denotes the language entered. This allows you to alter the display of the code, both for all code blocks and specific languages, through the use of css.

A few rules are applied to the language name when it is outputted as the class name of the pre tag.

  • The language name is converted to all lower cases.
  • White spaces are stripped.
  • # is converted to “sharp”.
  • . is converted to “dot”.
  • + is converted to “plus”.

For example, this means <code c#> will produce <pre class=“code csharp”>.

Note: <nowiki> tags are placed around the code, so that any wiki syntax in the code will not be parsed by the wiki engine.

Supported languages: ASPX, C, C++, C#, COBOL, Eiffel, Fortran, Haskell, HTML, Java, JavaScript, Mercury, MSIL, Pascal, Perl, PHP, Python, Ruby, SQL, Visual Basic, VBScript, VB.NET, XML.

Installation

  1. Download Syntax Highlighter.
  2. Extract the uploads.zip folder into your root wiki directory.
    • Definitions.xml should go in to your root directory.
    • Lonwas.Highlight.dll should go in to your bin directory.
  3. Log into your Wiki’s administration panel.
  4. Click on the Providers tab.
  5. Under Add new Providers click on browse and select TimBellette.ScrewTurnSyntaxHighlighter.dll and click upload.
    • If your Definitions.xml file is not in the default location, or has been renamed, it will show up as disabled.
      1. Click Syntax Highlighter in your providers list and click Configure.
      2. Enter in the url of the uploaded Definitions.xml file (E.G. http://yoursite.com/wiki/Definitions.xml) and click save.
      3. Click Enable to enable the Syntax Highlighter.
  6. You’re Done.

History

  • [Version 1.2, released 2007-06-16]
    • Added default configuration setting.
  • [Version 1.1, released 2007-06-16]
    • Fixed wiki rendering bug.
    • Fixed css class names bug.
  • [Version 1.0, released 2007-06-15]
    • First released.

Licensing

Copyright ©2007 Tim Bellette. All rights reserved.

 

16 Responses to “ScrewTurn Syntax Highlighter”

  1. Hello, interesting plugin. I get a 404 when trying to download.

    Thanks,
    Alex

  2. Tim Bellette says:

    Hi Alex, Thanks for letting me know the download was not working. It has been fixed and should work now. Thanks, Tim.

  3. Brendan Rice says:

    Hi,

    Firstly thanks for making this public, I have found it excellent and have been using it to build up a code library.

    I have set up a new WIKI and I get the following error when doing step 5.2. Can you help please?

    Thanks,

    Brendan

    http://www.???.com/Admin.aspxSystem thrown System.Net.WebExceptionThe remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse() at System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials) at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver) at System.Threading.CompressedStack.runTryCode(Object userData) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state) at System.Xml.XmlTextReaderImpl.OpenUrl() at System.Xml.XmlTextReaderImpl.Read() at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at System.Xml.XmlDocument.Load(String filename) at TimBellette.ScrewTurnSyntaxHighlighter.SyntaxHighlighter.Init(IHost host, String config) at ScrewTurn.Wiki.Admin.btnSaveProviderConfiguration_Click(Object sender, EventArgs e) in c:\Web\Wiki\Admin.aspx.cs:line 2045 at System.Web.UI.WebControls.Button.OnClick(EventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

  4. Tim Bellette says:

    Hi Brendan,

    Thanks for your comments :)

    It looks like there could be a permissions exception occurring when the plugin is trying to read the xml file. Please check security permissions to his file and ensure asp.net has read access.

    Cheers,
    Tim

  5. Brendan Rice says:

    Hi Tim,

    you are right about the permissions, it is sorted now, may be an idea to include the permissions step in the instructions, it is easily overlooked.

    Good job with the plug in.

    Thanks again,

    Brendan

  6. James Patterson says:

    Hi Tim,

    Any plans to update the highlighter so that it works with v3?

  7. Michal says:

    Hello, everytime I have “<script” inside “code aspx” tag I get “Unallowed SCRIPT tag detected in the content”. Any chance your plugin could bypass that?

  8. Hi Tim,

    It works now thanks.

    @Michal:
    Could you convert your tags to HTML e.g. < to < etc. and then put that in the tags...?

  9. Hi Tim,

    Excellent syntax highlighter, we’re using it on our internal R&D wiki. We’ve run it (and Lonwas.Highlight, which seems to have disappeared off the ‘net) through a disassembler so we could update the code for ScrewTurn 3.

    Thanks!

  10. User says:

    If you copy and paste the parsed code from Firefox work, but you copy and paste from IE some line don’t copy the CR/LF

  11. Chris Kirby says:

    Hello,

    What can i do when one of the xml tags I’m trying to format is string data? is there some way i can escape that so that the will format my xml properly?

    Excellent plugin btw!

    Thank you, Chris

  12. Chris Kirby says:

    @Chris Kirby
    for some reason the site reformatted my question.. I’ll try escaping:

    trying to format: >code$lt;my data$gt/code$lt; using the code XML wrapper.

  13. Thank you says:

    Hi Tim,

    Thank you. We’re using your *excellent* Syntax Highlighter plugin for over a year now in our code library. Customization through the use of an XML file was a godsend! It made possible to define our own scheme.

  14. Softlion says:

    I’ve upgraded the syntax highlighter for ScrewTurn wiki v3 RC1.
    Download it from there:

    http://www.softlion.com/blogs/post/2009/07/24/Syntax-Highlighter-for-ScrewTurn-wiki-v3.aspx

  15. Richard says:

    Hi Tim,

    I’m having an issue with the following code:


    Row
    Id
    Name

    [EACHROW]

    [#RowNumber][DepartmentId][Name]
    [/EACHROW]

    It seems the gets collapsed to just

Leave a Reply