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 Kost 29f909a589 fix(296): parse with lost repeated closing tag (#297)
* fix: extract node list ot separate file, fix nested parsing

* chore:  node list tests

* fix: nested tags parsing

* chore: changeset

* chore: remove unused files

* chore: disable publish on every commit
2025-10-14 04:11:19 +02:00
..
2024-04-23 21:11:14 +02:00
2024-04-23 21:11:14 +02:00
2021-11-29 00:33:06 +02:00
2023-10-23 13:21:56 +02:00
2024-04-23 21:11:14 +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>