catarsa.com
čeština English (United Kingdom)
Story

User: NotSigned (NotSigned)

Logon: Logon

Language: en-US

Wiki .NET Parser II.

The Wiki .NET Parser II. converts the Wiki .NET syntax to the HTML result. The parsing engine is based on the ultimate ANTLR project. Wiki .NET Parser is an Open Source, written in C#, for free...

The Wiki .NET Parser II

Wiki .NET Parser is available on the Nuget.org :

https://nuget.org/packages/WikiNetParser

Downloads (version 2.5.1)

  1. WikiNetParser_build.zip - binnaries
  2. WikiNetParser_source.zip - source code
  3. Wiki .NET Syntax
var result = new ProjectBase.Tools.Wiki.WikiConverter().ConvertToHtml(sourceText);

License

http://catarsa.com/Articles/Download/Any/License

Example

http://catarsa.com/Articles/Code/Wiki-Example

Wiki .NET Parser - about

The Wiki .NET Parser is written, using and powered by the ANTLR project. This is an ultimate text parser, ready to be used in many scenarios when the written text must be understood and then converted. One of the well known projects using the ANTLR as the HQL parser is the NHibernate  (Hibernate) project.

The Wiki .NET Parser is currently targeting the .NET 3.5 framework. There is really a lot of code used to parse the Wiki .NET Syntax. But that all was generated with the ANTLRWorks tool and with a few lines of the Lexer, Parser and AST Parser syntax. In fact these 3 grammar files (and one partial class extender written in C#) make up the complete Wiki .NET Parser.

Test it, and you will be fascinated how easy is to use not only the Wiki .NET Parser (there is in fact only one method:)

var result = new ProjectBase.Tools.Wiki.WikiConverter().ConvertToHtml(sourceText);

but also to adjust that all with the ANTLRWorks tool.

Wiki .NET Syntax

To get started, read this Wiki .NET Syntax revealed.

Comments
Name
Maxim
Inserted
5/10/2012 8:45:00 AM
MismatchedTokenException when running on wikitext

Hi,

I try to run the parser on the below text and get a MismatcherTokenException. What is wrong?

{{Redirect|Anarchist|the fictional character|Anarchist (comics)}}

{{Redirect|Anarchists}}

{{Anarchism sidebar}}

{{Libertarianism sidebar}}

'''Anarchism''' is generally defined as the olitical philosophy]] which holds the tate (polity)|state]] to be undesirable, unnecessary, and harmful,<ref name="definition">

Name
Radim Köhler
Inserted
5/10/2012 8:06:00 PM
incorrect syntax

Hi,

to be honest, this is a bit challenging to find out.

Well, this wiki engine, is based on parsing text to create its structured model (as for example valid HTML is)

This means, that in comparison with other engines, which work over string replacing, in this case, ANTLR3 firstly tries to convert the text into the AST (abstract syntax tree) the result is then walked through and converted into HTML.

So this boring preface should help me to explain this.

Take your text piece by piece. Find out which part does this exception. Check the rules (Wiki .NET syntax) and find out what's wrong.

Not as good as I wish, I know. I do not have better answer

One example:

Here I write and cite "that someone \r\n said these words".

this parser will have a problem, while tries to find a quoted text without the symbol of the end of line (\r\n). And will break.

While this will work:

Here I write and cite "that someone said these words".

Radim Köhler

PS: again, this parser is mostly about creating AST, rather then string replacing. It allows to efficiently use the power of ANTLR, while needs some compromises

Name
Paul
Inserted
12/17/2012 10:11:00 PM
Nuget Package

I couldn't find this as a nuget packge - and it is a perfect target for nuget.

Add Comment
Comment
* (required field)
Detail view Printable view