KEMU Documents server
JavaScript failed !
So this is static version of this website.
This website works a lot better in JavaScript enabled browser.
Please enable JavaScript.


This section is related to JavaScript (Node.js) implementation of Kemu BB-Code.

We started node.js implementation of BB2 in 2014 as internal project based on our existing PHP implementation.
We published it in 2015 as npm package.

All the code of KBB is written in CoffeeScript and so are the examples below. Obviously you can use KBB from your plain JavaScript code.
CoffeeScript is not mandatory for your application code.

The node.js package is publicly available on Node Package Manager as bb2

The source code is published as github repo

All the example code given here can be found in node_package_check of github repository.


KBB is written in CoffeeScript, so it needs your node.js to support CoffeeScript notation. If you don't have CoffeeScript installed:
ⓘ Example usage:
npm install -g coffee-script

To install KBB:
ⓘ Example usage:
npm install bb2

Simple code

The code:
ⓘ Example usage:
BBCodeHtml = require('bb2').BBCodeHtml
bb = new BBCodeHtml()
console.log bb.parse('visible [0]invisible[1] [b]bold[/] [i]italic[/]')
prints to console:
ⓘ Example usage:
visible  bold italic

So, simple usage pattern is:
  • Load bb2
  • Create instance of BBCodeHtml
  • Call parse()

Config - usage example

The instance of BBCodeHtml holds parsing config. The config should be passed in constructor (config details explained in config section):
ⓘ Example usage:
BBCodeHtml = require('bb2').BBCodeHtml
config = {innerUrl: ''}
bb = new BBCodeHtml(config)
console.log bb.parse('AAAAA [linkin url="the_internal_link"]BBBB[/] CCCC')
prints to console
ⓘ Example usage:
AAAAA <a href="">BBBB</a> CCCC

Config - defaults and overriding them

This is default config as for version 1.0.2
ⓘ Example usage:
allowDirectHtml: false
innerUrl: ''
imgUrl: ''
lbToBrEnabled: true
blockOnClickOnInternalLinks: false
passLinkDataOnInternalLinks: false

To override some of default values, just pass object with needed values to the constructor. For example:
ⓘ Example usage:
config = {
    innerUrl: ''
    lbToBrEnabled: false
bb = new BBCodeHtml(config)

Config - parameters reference

  • allowDirectHtml (true/false) - controls direct HTML entities obfuscation (for example for security reason)
    • true - direct HTML entities are in pass-through mode.
    • false - direct HTML entities are not allowed
      In this mode, characters in set of <, >, &, ", ' are converted to their corresponding HTML entities, e.g. < is rendered as &lt;
  • innerUrl (string): sets the prefix for internal links used by [linkin] bb-tags.
    For example: if innerUrl is '', then
    ⓘ Example usage:
    [linkin url="test"]xxx[/]
    is renered as
    ⓘ Example usage:
    <a href="">xxx</a>
  • imgUrl (string): sets the prefix for image urls, in BB tags like [img]
    For example: if imgUrl is '', then
    ⓘ Example usage:
    [img url="test.jpg"]
    is renered as
    ⓘ Example usage:
    <img src=""/>
  • lbToBrEnabled (true/false) - line-break conversion mode
    • true - all line-break (linux line-feed, '\n', ASCII 10) characters, are converted to <br> HTML code
    • false - line breaks are simply ignored
  • blockOnClickOnInternalLinks (true/false)
    This is useful when default browser "click" control on internal links is to be overriden by JavaScript code (like Ajax/Websocket loaders).
    • true - the click event for internal links ([linkin]) is overriden in HTML and returns false to browser, so default browser action is disabled
    • false - normal behaviour
  • passLinkDataOnInternalLinks (true/false)
    This is useful when default browser "click" control on internal links is to be overriden by JavaScript code (like Ajax/Websocket loaders).
    • true - store plain url of link as "data-linkin" parameter of HTML tag - very useful for link routing on browser side
    • false - normal behaviour

Help and feedback

If something doesn't work, you just have questions or request for upgrade, don't hesitate to contact us.