Skip to content

About

Simple, configurable BBCode to HTML parser for JavaScript with custom codes and attributes.

Topics

Resources

Stars

26 stars

Watchers

1 watching

Forks

Latest commit

 

History

41 Commits

Folders and files

Repository files navigation

js-bbcode-parser

Lightweight BBCode parser for browsers and Node.js. It turns BBCode into HTML via regular expressions, ships a ready-made parser with the usual codes and lets you define your own.

Documentation: https://www.marco-starker.de/en/projects/js-bbcode-parser/docs (Deutsch: https://www.marco-starker.de/de/projekte/js-bbcode-parser/doku)

Caution

js-bbcode-parser does not sanitize the input against XSS. Sanitize the output (e.g. with DOMPurify) before rendering text that comes from users.

Quick start

npm i js-bbcode-parser
import bbCodeParser from 'js-bbcode-parser';

bbCodeParser.parse('[b]Hello[/b] [url=https://example.com]world[/url]');
// <strong>Hello</strong> <a href="https://example.com">world</a>

Custom codes: key is a regular expression as a string, value is the replacement.

import BBCodeParser from 'js-bbcode-parser/src/index.js';

const parser = new BBCodeParser({
    '\\[br\\]':             '<br>',
    '\\[b\\](.+?)\\[/b\\]': '<strong>$1</strong>',
});

License

MIT

About

Simple, configurable BBCode to HTML parser for JavaScript with custom codes and attributes.

Topics

Resources

Stars

26 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages