mirror of
https://github.com/tenrok/BBob.git
synced 2026-05-15 11:59:37 +03:00
40848747d4
Closes #134 * feat: Add start and end positions of tag nodes Improves accuracy of row/col error reporting. Now targets the start of the relevant token instead of the end. * Simplify language for TagNode and Token * Update static TagNode.create to ingest setStart() logic improve readability of end pos offset for no attr tags
@bbob/parser
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>