BBDecode ======== Extracted from a production application I co-authored, BBDecode will take a string of BBCode and parse it into its XHTML representation:: >>> from bbdecode import bbdecode >>> bbdecode('[b]Hello[/b]') <b>Hello</b> BBDecode attempts to emit valid XHTML even from improperly nested BBCode input or input with unclosed tags, and does a fair job of it:: >>> bbdecode('[b]Bold [i]Bold Italic[/b]') <b>Bold <i>Bold Italic</i></b> Features -------- The current implementation contains handlers for a common subset of tags found on most forum softwares, with some additional features like more optional arguments. In addition to the normal argument supplied to some bbcode tags in many bbcode dialects (such as in `[quote="Author"]`) bbdecode can take optional arguments in an HTML-style key=value form, and can take either quoted or unquoted strings. For example:: `[img width=28 height="40"]http://www.site.com/a.jpg[/img] BBDecode is theoretically unicode-friendly, but this remains to be seen once things are tested. Future ------ The future of this project is to add some more useful tags, and make the ability to add/remove/customize the available tags so that this library can be used in support of other forums In addition, while BBDecode currently requires pyparsing, it may be switched to another parser like TPG or a custom parser in the future. The parser is currently recursive descent and emits output directly to the stream, whether it will in the future build an intermediate parse tree I am not sure. Recursive descent parsing can be abused by users who just continuously nest tags to break the parser by causing a stack overflow, this could be mitigated by setting max depths in the parser.