2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-05-15 11:59:37 +03:00
Files
bbob/packages/bbob-parser
Nikolay Kostyurin c5aa4f08d1 Publish
- @bbob/cli@2.0.2
 - @bbob/core@2.0.2
 - @bbob/html@2.1.1
 - @bbob/parser@2.2.0
 - @bbob/preset-html5@2.1.1
 - @bbob/preset-react@2.0.2
 - @bbob/react@2.0.2
2018-10-07 22:27:07 +02:00
..
2018-10-07 22:27:07 +02:00
2018-10-07 22:27:07 +02:00

@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>