*** NOTE – The author discontinued this tool ***
BBCodes are well known through forum communities and is the abbreviation for Bulletin Board Code. The tags are usually indicated by rectangular brackets surrounding a keyword, the use of it is to make text formatting possible without having to write HTML. It’s safer, comfortable and easy to implent.
Every tag is being translated into markup language that web browsers understand, this is where Codeparser.NET joins the game:
codeparser.net is a free .NET based and highly configurable parser for BBCode. Since it is a component, it can be integrated with Windows as well as with web applications and web services.
It’s pretty easy to implent and you will find some pre-made examples for parsing Smilies, Lists, Links, Code and much more. Alternative replacements, syntax highlighting, invalid tag configuration, expression replacements, things you don’t want to miss when dealing with BBCodes. I recently used it for two ASP.NET Web Applications, it’s pretty straight forward. Define some rules, save them as parser.xml, create the parser object and just starting parsing:
parser.Parse(txt);
If you use the dll for communities there’s just one thing to look after, people forget closing specific tags sometimes which will lead to an exception at the moment. One of the developer, Golo Roden, already told me that they are working on a better solution for this in a future version, for now just use a try/catch block if you deal with user input and do not validate the proper tag closings yourself:
protected string ParseText(string txt)
{
try
{
return parser.Parse(txt);
}
catch
{
return txt;
}
}
Here is a example of a parser.xml which is parsing Links and text formattings:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<parser>
<throwExceptionOnInvalidTag value="False" />
</parser>
<tags>
<tag name="url" replacement="<a href="{1}">{0}</a>"
alternativeReplacement="<a href="{0}">{0}</a>" />
<tag name="mail" replacement="<a href="mailto:{1}">{0}</a>" />
<tag name="email" replacement="<a href="mailto:{1}">{0}</a>" />
<tag name="b" replacement="<span style="font-weight:bold;">{0}</span>" />
<tag name="i" replacement="<span style="font-style:italic;">{0}</span>" />
<tag name="u" replacement="<span style="text-decoration:underline;">{0}</span>" />
<tag name="quote" replacement="<table border="0" cellpadding="8" cellspacing="0"><tbody><tr><td class="alt2" style="border: 1px inset ;">{0}</td></tr></tbody></table>" />
</tags>
</configuration>
I didn’t face any other problems after running it for about one month now, good job and I’m happy to recommend it to you guys! Head over to the -removed- homepage for more.
5 comments ↓
Hi Andreas,
Could you also post the parser.xml?
Cheers,
Paul
Hi Paul,
I just posted an example, you can find more on the Codeparser Homepage!
Cheers,
Andreas
Hi Andreas,
Thanks for the tip! I’ve tried it out and works perfect, except for one little thing. I’m trying to use the Text.Code extension but receive this error:
Exception of type ‘codeparser.net.Exceptions.InvalidTagNestingException’ was thrown.
Any ideas?
Regards,
Björn
Hi Björn,
if you want you may send your not-working example to me, and I’ll have a look at it … perhaps there’s a bug in codeparser.net we do not know of yet, perhaps it’s simply a configuration issue …
Just contact me via email webmaster@goloroden.de …
Cheerio,
Golo
(Developer of codeparser.net)
Hi Golo,
I managed to find the error. I was using a class to truncate the text to 100 words and when the post exceeded this and I was using BBCode the exception was thrown since it did not have an ending tag.
The issue is now fixed.
Regards,
Bjorn
Leave a Comment