Any good javascript BBCode parser?

Drevak picture Drevak · Dec 3, 2009 · Viewed 11.5k times · Source

Currently i'm parsing bbcode server side but i'd like to show a preview just like this site does.

If I process the bbcode serverside using ajax it's a bit laggy, so i thought doing it client side, to just show the preview.

Do you guys know any bbcode parser written in javascript?

Answer

Art McBain picture Art McBain · Jan 15, 2010

It is a bit late, and the question has certainly been answered. However if you are still open to suggestions, and have not yet spent your time converting the indicated parser from C# to JavaScript, I have written a parser (originally in PHP) which I converted myself[2] to JavaScript. It is available at bitbucket under the 3-clause BSD license. The parser seems to be reasonably fast, but I haven't performed any analysis on its speed.

It may not be as flexible in some ways as other possible projects out there, but it does allow defining your own codes ("bb-code" or not, with quite a few properties), and is also all contained within the one file. This is not a simple find-and-replace parser, and is not based on regex.

If this is of any interest to you, it might save you from having to convert that other library. Technically, I'm a relative "unknown", but that's the great things about JS/OSS: you can check out the source to see what I've done.

[2] As a result, there are a few remaining "compatibility functions", but I rewrote things which had native equivalents available.