@bbob/parser
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/bbob__parser package

3.0.2 • Public • Published

@bbob/parser

install size Known Vulnerabilities

Parses BBCode and returns array AST tree

Valid for use with posthtml-render

Install

npm i @bbob/parser

Usage

API

import { parse } from '@bbob/parser'

const options = {
    onlyAllowTags: ['url', 'h'],
    onError: (err) => console.warn(err.message, err.lineNumber, err.columnNumber)
};
const ast = parse('[url=https://github.com]hello world![/url]', options)

Results to

[
    {
        "tag": "url",
        "attrs": {
            "url": "https://github.com"
        },
        "content": ["hello", " ", "world!"]
    }
]

PostHTML

import render from 'posthtml-render'
import { parse } from '@bbob/parser'

const options = {
    onlyAllowTags: ['url', 'h'],
    onError: (err) => console.warn(err.message, err.lineNumber, err.columnNumber)
};

const ast = parse('[url=https://github.com]hello world![/url]', options);
const html = render(ast) // <url url="https://github.com">hello world!</url>

/@bbob/parser/

    Package Sidebar

    Install

    npm i @bbob/parser

    Weekly Downloads

    18,854

    Version

    3.0.2

    License

    MIT

    Unpacked Size

    142 kB

    Total Files

    22

    Last publish

    Collaborators

    • jilizart