WikiRenderer is a library that converts text marked up via WikiFormatting rules to HTML. It has no dependency on any specific web app implementation, which means it is very easy to reuse in multiple wiki clones. This SampleWiki is just one such clone.

Unlike many other wiki clone implementations, WikiRenderer is not built as a series of regular expressions. In order to minimize memory usage, the HTML is produced by a single pass over the input wiki marked up text. This approach minimizes the number of interim representations of the wiki text are created while generating the final HTML markup.

The original version (v0.2) of WikiRenderer interpreted the wiki text on the fly. This rendering code is based on Eddie Edwards' WikiServer. WikiServer was originally written in C++, but I ported the code to C# so I can use it with ASP.NET.

The current version (v0.5) of WikiRenderer uses a a lexical scanner (generated with Brad Merril's CsLex) to parse the wiki text. HTML markup can be generated directly or the wiki text can be used to generate a compiled class similar to how ASP.NET WebForm pages are compiled.

WikiRenderer consists of the following classes:
  • WikiScanner - Lexical scanner generated by CsLex by BradMerrill. This class reads the wiki text and breaks it into a series of tokens. This turned out to be significantly easier than I expected and I expect it will be easier to enhance with new WikiFormatting rules this way in the future.
  • WikiRenderer - Essentially, WikiRenderer is a parser for the wiki text "language". It consumes tokens from WikiScanner and makes calls to WikiWriter to output the formatted language.
  • WikiWriter - Abstracts away the generation of formatted text. Theoretically, this enables the future use of alternative markup languages other than HTML. However, this also made it very easy to generate precompiled wiki pages (explained below)
    • HtmlWikiWriter - outputs the WikiRenderer calls as HTML
    • CodeWikiWriter - Generates code to call WikiWriter methods via CodeDom. This enables compiling of wiki pages for multiple uses.
  • WikiGenerator - Given a stream of wiki text, WikiGenerator will generate a class that derives from WikiPage that makes calls to a WikiWriter to generate the formatted page content. This class can be cached on the web server between web requests for higher performance. Note, compilation of wiki pages is entirely optional. Using the HtmlWikiWriter with WikiRenderer, you can write HTML to an arbitrary stream from a stream of wiki text. In the associated SampleWiki implementation, only the current version of any wiki page is compiled - older versions are renderered as requested.
  • WikiPage - abstract base class for any compiled wiki pages generated by WikiGenerator. Supports wikiword prevalidation, meaning the compiled page makes a single call to the delegate, passing in the list of wikiwords in a wikipage and getting back a hashtable with each page's status (does it exist and what's the link). This improves performance of pages that have the same wikiword multiple times (like this one!) and enables the wiki host to make a single round trip to the database to retrieve all the wiki pages status.

Last edited Jul 30, 2007 at 7:20 PM by harrypierson, version 2

Comments

No comments yet.