1.0.5 • Published 5 years ago

bbcode-async v1.0.5

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

bbcode-async

A simple BBCode parser/renderer with async, designed for NodeJS.

-- NOT PRODUCTION YET --

Installation

npm i bbcode-async

Usage

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

optiondefaultfunction
replaceNewLinefalsereplaces each \r and \n with
dataAttributesfalseallow usage of data-xyz="data"
classesfalseallows to define classes in BBCode tags
classPrefixnulladds 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

tagrendered
[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);
})
1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago