JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q30461F
  • License MIT

Asnyc parser for [bb]Code

Package Exports

  • bbcode-async

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (bbcode-async) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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

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);
})