A simple BBCode parser. It's "bitter" because it's written in CoffeeScript, you see.
The concept is to support some form of "generic" BBCode out of the box that covers the majority of software platforms out there, while being extensible enough that new BBCodes can be added without breaking anything.
Because it parses to a "DOM" it should be possible to export to destinations that aren't BBCode, for example, it should be possible to write a BBCode to Markdown translator.
It supports very simplistic BBCode at present:
[b]Bold[/b]
[i]Italic[/i]
[u]Underline[/u]
[url=https://www.github.com/]GitHub[/url]
Becomes:
<p><b>Bold</b><br>
<i>Italic</i><br>
<u>Underline</u><br>
<a href="https://www.github.com/">GitHub</a></p>
var bbcode = require('bitter-bbcode');
bbcode("Some [b]text[/b]");
// Result: "<p>Some <b>text</b></p>");
var bbcode = require('bitter-bbcode');
var parser = bbcode();
var bbdom = parser.parse("[b]Some BB Code[/b]");
blocks = bbdom.toBlocks();
blocks.toHTML();
This is currently targeted at supporting phpBB-style BBCode. The ultimate goal is to make it configurable enough that various BBCode styles can be supported, including a default "global" mode that accepts the majority of BBCode used by the majority of forums that support BBCode.
The following describes the BBCode available in popular BBCode implementations compared to this implementation. If the tag is in the table and unless otherwise noted, it is planned to be implemented in the future.
BBCode | Description | Supported? |
---|---|---|
[b] | Bold text | ✅ |
[i] | Italic text | ✅ |
[u] | Underline text | ✅ |
[s] | Strike-though text | ✅ |
[sub] | Subscript text | ✅ |
[super] | Superscript text | ✅ |
[fixed] | Fixed-width text | ❌ |
[color=color] | Text in the specified color | ❌ |
[size=size] | Change text size | ❌ |
[url] | Link | ✅ |
[url=url] | Link | ✅ |
[email] | Link an email address | ❌ |
[email=email] | Link an email address | ❌ |
[img] | Image | ✅ |
[timg] | Thumbnailed image | ❌¹ |
[flash] | Embedding flash content | ❌² |
[video] | Embedding video content | ❌¹ |
[list] | Unordered List | ✅ |
[list=1] | Numerically Ordered List | ✅ |
[list=a] | Alphabetically Ordered List | ✅ |
[quote] | Quote | ✅ |
[quote="name"] | Quote with a given name | ✅ |
[code] | BBCode ignored code block | ✅ |
[code=language] | BBCode ignored code block with syntax highlighting | |
[php] | Same as [code=php] | ❌ |
¹ It is unlikely this tag will ever be enabled by default
² It is unlikely that embedding Flash will ever be supported by this library
³ Syntax highlighting is not supported at present
Check out the [full comparison tables](compat/Comparison Tables.md) for details about how this library differs from other BBCode implementations.