1.0.5 • Published 7 years ago
bbcode-async v1.0.5
bbcode-async
A simple BBCode parser/renderer with async, designed for NodeJS.
-- NOT PRODUCTION YET --
Installation
npm i bbcode-asyncUsage
First, require this library
const bba = require('bbcode-async')
When it´s initiated, you can parse strings.
let string "[h1]Hello World[/h1] this is my text";
bba.parse(string, function(err, result) {
console.log(result);
// will output <h1>Hello World</h1> this is my text
})Options
| option | default | function |
|---|---|---|
| replaceNewLine | false | replaces each \r and \n with |
| dataAttributes | false | allow usage of data-xyz="data" |
| classes | false | allows to define classes in BBCode tags |
| classPrefix | null | adds a prefix to classes |
options can be passed by second attribute like:
let options = {
replaceNewLine: true
};
bba.parse(string, options, function(err, result) {
console.log(result);
}) Default Tags
| tag | rendered |
|---|---|
| [url=google.com]link[/url] | link |
| [email=example@example.com]email me[/email] | email me |
| [b]bold content[/b] | bold content |
| [i]italic content[/i] | italic content |
| [u]underlined content[/u] | underlined content |
| [s]strike-through content[/s] | strike-through content |
| [indent]quoted content[/indent] | quoted content |
| [list][/list] | alias for ul |
| [ul][/ul] | |
| [li][/li] | |
| [php]code content[/php] | |
| [javascript]code content[/javascript] | |
| [java]code content[/java] | |
| [ruby]code content[/ruby] | |
| [css]code content[/css] | |
| [python]code content[/python] | |
| [code]code content[/code] | |
| [color=black]colored content[/color] | |
| [h1]headline content[/h1] | |
| [h2..6]headline 2-6 content[/h2..6] | |
| [span]simple span content[/span] | |
| [p]simple paragraph content[/p] | |
| [img=http://link_to_my_image.jpg][/img] | |
| [center]centered content[/center] | |
| [left]left-alined content[/left] | |
| [right]left-alined content[/right] |
Custom Tags
Simple as easy to add you own custom tag
bba.registerTag('mytag', function(string, tag, attrs, value, tagDetails, done) {
return done(null, '<my-tag>' + value + '</mytag>');
})same for asynchronous custom tags
bba.registerTag('mytag', function(string, tag, attrs, value, tagDetails, done) {
// simulates an async call
setTimeout(function() {
return done(null, '<my-tag>' + value + '</mytag>');
}, 2000);
})