BBCode Parser

Parse BBCode into AST and convert into HTML

16.09.2025 itibariyledir. En son verisyonu görün.

Bu script direkt olarak kurulamaz. Başka scriptler için bir kütüphanedir ve meta yönergeleri içerir // @require https://update.greasyfork.org/scripts/549682/1661585/BBCode%20Parser.js

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

Yazar
PYUDNG
Versiyon
0.1
Oluşturulma
16.09.2025
Güncellenme
16.09.2025
Boyut
24,9 KB
Lisans
GPL-3.0-or-later

A BBCode parser without any built-in parsing rules, allowing users to implement their own rules.

Usage

1. First of all, create parser

const parser = new BBCodeParser();

2. Implement and register parsing rules

A rule for [url=URL]CONTENT[/url] and [url]URL_AS_CONTENT[/url] can be registered like this:

parser.register({
    'url': {
        openTag(params, content) {
            let url = params ?? content;
            url = url.startsWith('http://') || url.startsWith('https://') ? url : 'http://' + url;
            return `<a href="${ url }" target="_blank">`;
        },
        closeTag(params, content) {
            return '</a>'
        },
    }
});

A rule for [b]CONTENT[/b] can be registered like this:

parser.register({
    'b': {
        openTag(params, content) {
            return '<b>';
        },
        closeTag(params, content) {
            return '</b>';
        },
    },
});

And yes, they can be registered with one call:

parser.register({
    'url': {
        openTag(params, content) {
            let url = params ?? content;
            url = url.startsWith('http://') || url.startsWith('https://') ? url : 'http://' + url;
            return `<a href="${ url }" target="_blank">`;
        },
        closeTag(params, content) {
            return '</a>'
        },
    },
    'b': {
        openTag(params, content) {
            return '<b>';
        },
        closeTag(params, content) {
            return '</b>';
        },
    },
});

3. Parse bbcode (and get html if need)

const result = parser.parse('[b]Hello[/b], [url=https://example.com/]bbcode[/url]');
// You can access html or ast / nodes in result object, like
console.log(result.html);

Types

Please refer to JSDoc in source code.