js-bbcode-parser
Simple and efficient bbcode parser.
Last updated 2 months ago by dasred .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install js-bbcode-parser 
SYNC missed versions from official npm registry.

bbcode-parser

General

This is a simple BBCode parser.

Installation

npm install js-bbcode-parser --save

How To

import bbCodeParser from 'js-bbcode-parser';

// use to create a clean parser
const parserA = bbCodeParser.create{}, {})

// configure the default parser with
bbCodeParser.setCodes({});

Usage

Default

A default BBCode parser is available.

import bbCodeParser from 'js-bbcode-parser';

console.log(bbCodeParser.parse('This is a text[br]with HTML Break.'));

following default BBCodes are supported

BBCode                                               | HTML
---------------------------------------------------- | -------------------------------------------------------------
[br]                                                 | <br>
[b]text[/b]                                          | <strong>text</strong>
[b class="fancy"]text[/b]                            | <strong class="fancy">text</strong>
[b data-value="10"]text[/b]                          | <strong data-value="10">text</strong>
[i]text[/i]                                          | <em>text</em>
[i class="fancy"]text[/i]                            | <em class="fancy">text</em>
[i data-value="10"]text[/i]                          | <em data-value="10">text</em>
[u]text[/u]                                          | <u>text</u>
[u class="fancy"]text[/u]                            | <u class="fancy">text</u>
[u data-value="10"]text[/u]                          | <u data-value="10">text</u>
[h1]text[/h1]                                        | <h1>text</h1>
[h1 class="fancy"]text[/h1]                          | <h1 class="fancy">text</h1>
[h1 data-value="10"]text[/h1]                        | <h1 data-value="10">text</h1>
[h2]text[/h2]                                        | <h2>text</h2>
[h2 class="fancy"]text[/h2]                          | <h2 class="fancy">text</h2>
[h2 data-value="10"]text[/h2]                        | <h2 data-value="10">text</h2>
[h3]text[/h3]                                        | <h3>text</h3>
[h3 class="fancy"]text[/h3]                          | <h3 class="fancy">text</h3>
[h3 data-value="10"]text[/h3]                        | <h3 data-value="10">text</h3>
[h4]text[/h4]                                        | <h4>text</h4>
[h4 class="fancy"]text[/h4]                          | <h4 class="fancy">text</h4>
[h4 data-value="10"]text[/h4]                        | <h4 data-value="10">text</h4>
[h5]text[/h5]                                        | <h5>text</h5>
[h5 class="fancy"]text[/h5]                          | <h5 class="fancy">text</h5>
[h5 data-value="10"]text[/h5]                        | <h5 data-value="10">text</h5>
[h6]text[/h6]                                        | <h6>text</h6>
[h6 class="fancy"]text[/h6]                          | <h6 class="fancy">text</h6>
[h6 data-value="10"]text[/h6]                        | <h6 data-value="10">text</h6>
[p]text[/p]                                          | <p>text</p>
[p class="fancy"]text[/p]                            | <p class="fancy">text</p>
[p data-value="10"]text[/p]                          | <p data-value="10">text</p>
[color=#FF0000]text[/color]                          | <span style="color:#FF0000">text</span>
[size=9]text[/size]                                  | <span style="font-size:9px">text</span>
[img]https://www.example.com/image.jpg[/img]         | <img src="https://www.example.com/image.jpg">
[img=https://www.example.com/image.jpg]              | <img src="https://www.example.com/image.jpg">
[email]info@example.com[/email]                      | <a href="mailto:info@example.com">info@example.com</a>
[email=info@example.com]text[/email]                 | <a href="mailto:info@example.com">text</a>
[url]https://www.example.com[/url]                   | <a href="https://www.example.com">https://www.example.com</a>
[url=alert('hello world')|onclick]text[/url]         | <a onclick="alert('hello world')">text</a>
[url=https://www.example.com target=_base]text[/url] | <a href="https://www.example.com" target="_base">text</a>
[url=https://www.example.com]text[/url]              | <a href="https://www.example.com">text</a>
[a=anker]text[/a]                                    | <a href="#anker" name="anker">text</a>
[list]text[/list]                                    | <ul>text</ul> 
[*]text[/*]                                          | <li>text</li>

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.

import bbCodeParser from 'js-bbcode-parser';

const parser = bbCodeParser.create({
    '\\[br\\]': '<br>'
});
console.log(parser.parse('This is a text[br]with HTML Break.'));

Current Tags

  • 3.0.2                                ...           latest (2 months ago)

9 Versions

  • 3.0.2                                ...           2 months ago
  • 3.0.1                                ...           2 months ago
  • 3.0.0                                ...           4 months ago
  • 2.0.2                                ...           6 months ago
  • 2.0.1                                ...           7 months ago
  • 2.0.0                                ...           a year ago
  • 1.0.9                                ...           a year ago
  • 1.0.8                                ...           a year ago
  • 1.0.7                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 2
Last Day 0
Last Week 0
Last Month 11
Dependencies (0)
None

Copyright 2014 - 2017 © taobao.org |