Simple and efficient bbcode parser.
npm install js-bbcode-parserNOTE: js-bbcode-parser does not purify the user input for xss.
bash
npm install js-bbcode-parser --save
`How To
`javascript
// this imports the default parser
import bbCodeParser from 'js-bbcode-parser';
// this import the class constructor of the parser
import BBCodeParser from 'js-bbcode-parser/src/index.js';// use to create a clean parser
const parserA = new BBCodeParser({});
// configure the default parser with
bbCodeParser.setCodes({});
`Usage
Default
A default BBCode parser is available.
`javascript
import bbCodeParser from 'js-bbcode-parser';console.log(bbCodeParser.parse('This is a text[br]with HTML Break.'));
`following default BBCodes are supported
`text
BBCode | HTML
---------------------------------------------------- | -------------------------------------------------------------
[br] |
[b]text[/b] | text
[b class="fancy"]text[/b] | text
[b data-value="10"]text[/b] | text
[i]text[/i] | text
[i class="fancy"]text[/i] | text
[i data-value="10"]text[/i] | text
[u]text[/u] | text
[u class="fancy"]text[/u] | text
[u data-value="10"]text[/u] | text
[h1]text[/h1] | text
[h1 class="fancy"]text[/h1] | text
[h1 data-value="10"]text[/h1] | text
[h2]text[/h2] | text
[h2 class="fancy"]text[/h2] | text
[h2 data-value="10"]text[/h2] | text
[h3]text[/h3] | text
[h3 class="fancy"]text[/h3] | text
[h3 data-value="10"]text[/h3] | text
[h4]text[/h4] | text
[h4 class="fancy"]text[/h4] | text
[h4 data-value="10"]text[/h4] | text
[h5]text[/h5] | text
[h5 class="fancy"]text[/h5] | text
[h5 data-value="10"]text[/h5] | text
[h6]text[/h6] | text
[h6 class="fancy"]text[/h6] | text
[h6 data-value="10"]text[/h6] | text
[p]text[/p] | text
[p class="fancy"]text[/p] | text
[p data-value="10"]text[/p] | text
[color=#FF0000]text[/color] | text
[size=9]text[/size] | text
[img]https://www.example.com/image.jpg[/img] | 
[img=https://www.example.com/image.jpg] | 
[email]info@example.com[/email] | info@example.com
[email=info@example.com]text[/email] | text
[url]https://www.example.com[/url] | https://www.example.com
[url=alert('hello world')|onclick]text[/url] | text
[url=https://www.example.com target=_base]text[/url] | text
[url=https://www.example.com]text[/url] | text
[a=anker]text[/a] | text
[list]text[/list] | text
[]text[/] | text
`Own BBCodes
You can provide your own BBCodes. The key of the codes object must be a regex part and the value is the replacement.`javascript
import BBCodeParser from 'js-bbcode-parser/src/index.js';const parser = new BBCodeParser({
'\\[br\\]': '
'
});
console.log(parser.parse('This is a text[br]with HTML Break.'));
``