Skip to content
Fully documented and Unit tested .NET Standard 2.0 BBCode to HTML parser.
Branch: master
Clone or download
Pull request Compare This branch is 23 commits ahead of Pablissimo:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Codekicker.BBCode is a stable and fast BBCode-Parser for .NET. It can transform any BBCode into HTML or into an in-memory syntax tree that can be analyzed or translated. All tags are fully customizable, nothing is hardcoded.

The design goals of Codekicker.BBCode were

  • Stable - it never ever crashes
  • Safe - it does not let through unsafe HTML like <script> under any circumstances
  • Performance - it is meant to be used in production
  • Easy to use - Just call BBCode.ToHtml("[url=][url]")
  • Customizable - Customizing the translation of every tag is easy and flexible
  • Error messages - the messages are available in English and German. Language contributions are welcome.


via NuGet

PM > Install-Package PoLaKoSz.CodeKicker.BBCode

Getting started

There is no built-in parser rule but You can make your own in 10 sec, so let's start: To make a parsing rule You will need to initialize a new BBTag class. For instance if You have simple tag like [b]

[b]My bold text.[/b]

and You want to parse it to this

<strong>My bold text.</strong>

You only need to write

new BBTag("b", "<strong>", "</strong>")

But what if You need to extract data to a specific attribute into the HTML tag?


Given this BBCode input

[url= class=jsCanModifyThis]Official CodeKicker parser link[/url]

which should be parsed to this HTML code

<a href="" class="jsCanModifyThis">Official CodeKicker parser link</a>

You need to pass BBAttribute objects into the BBTag constructor like this

var attrs = new BBAttribute[]
    new BBAttribute("url", ""),
    new BBAttribute("className", "class")
new BBTag("url", "<a href=\"${url}\" class=\"${className}\">", "</a>", attrs),

to extract the link's URL and the class name from it.


Now that You can build custom parsing rules You only need to know how to perform an actual BBCode to HTML parsing. First make a parser rule collection

var bbTags = new List<BBTag>()
    new BBTag("b", "<strong>", "</strong>"),
    new BBTag("i", "<em>", "</em>"),
    new BBTag("u", "<span style=\"text-decoration: line-through\">", "</span>"),

    new BBTag("list", "<ul>", "</ul>") { SuppressFirstNewlineAfter = true },
    new BBTag("li", "<li>", "</li>", true, false),

    new BBTag("url", "<a href=\"${url}\">", "</a>",
        new BBAttribute("url", "")),

    new BBTag("code", "<pre class=\"prettyprint\">", "</pre>")
        StopProcessing = true,
        SuppressFirstNewlineAfter = true

Initialize the parser

var parser = new BBCodeParser(bbTags);

And execute the parser on a BBCode

string output = parser.ToHtml(
    "[i]Not to be confused with [url=]Text formatting[/url]." +
    "\"Rich text\" redirects here. For text/richtext, see [url=]Enriched text.[/url][/i]" +

    "[list]" +
        "[li]Capitalization: I am NOT making this up.[/li]" +
        "[li]Surrounding with underscores: I am _not_ making this up.[/li]" +
        "[li]Surrounding with asterisks: I am *not* making this up.[/li]" +
        "[li]Spacing: I am n o t making this up.[/li]" +

And the output should be this (in one line)

<em>Not to be confused with <a href=\"\">Text formatting</a>.
"&quot;Rich text&quot; redirects here. For text/richtext, see <a href=\"\">Enriched text.</a></em>

    <li>Capitalization: I am NOT making this up.</li>
    <li>Surrounding with underscores: I am _not_ making this up.</li>
    <li>Surrounding with asterisks: I am *not* making this up.</li>
    <li>Spacing: I am n o t making this up.</li>

For more info check out the Documentation.

You can’t perform that action at this time.