0.0.1 • Published 8 years ago

bitter-bbcode v0.0.1

Weekly downloads
5
License
MIT
Repository
github
Last release
8 years ago

bitter-bbcode

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>

Basic Usage

var bbcode = require('bitter-bbcode');

bbcode("Some [b]text[/b]");
// Result: "<p>Some <b>text</b></p>");

More advanced use

var bbcode = require('bitter-bbcode');
var parser = bbcode();
var bbdom = parser.parse("[b]Some BB Code[/b]");
blocks = bbdom.toBlocks();
blocks.toHTML();

BBCode Compatibility

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.

Supported BBCode Table

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.

BBCodeDescriptionSupported?
bBold text:white_check_mark:
iItalic text:white_check_mark:
uUnderline text:white_check_mark:
sStrike-though text:white_check_mark:
subSubscript text:white_check_mark:
superSuperscript text:white_check_mark:
fixedFixed-width text:x:
color=colorText in the specified color:x:
size=sizeChange text size:x:
urlLink:white_check_mark:
url=urlLink:white_check_mark:
emailLink an email address:x:
email=emailLink an email address:x:
imgImage:white_check_mark:
timgThumbnailed image:x:¹
flashEmbedding flash content:x:²
videoEmbedding video content:x:¹
listUnordered List:white_check_mark:
list=1Numerically Ordered List:white_check_mark:
list=aAlphabetically Ordered List:white_check_mark:
quoteQuote:white_check_mark:
quote="name"Quote with a given name:white_check_mark:
codeBBCode ignored code block:white_check_mark:
code=languageBBCode ignored code block with syntax highlighting:warning:³
phpSame as code=php:x:

¹ 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

BBCode by bulletin board software

Check out the full comparison tables(compat/Comparison Tables.md) for details about how this library differs from other BBCode implementations.

0.0.1

8 years ago