bbcode

package
v0.26.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2025 License: AGPL-3.0 Imports: 1 Imported by: 0

README

BBCode Package

The bbcode package provides BBCode to HTML conversion functionality for the Dracory framework. It enables converting BBCode formatted text into clean, valid HTML output.

Features

  • Convert BBCode text to HTML
  • Support for common BBCode tags:
    • Text formatting ([b], [i], [u], [s])
    • Links ([url])
    • Images ([img])
    • Lists ([list], [ul], [ol])
    • Code blocks ([code])
    • Quotes ([quote])
    • Colors and sizes ([color], [size])
  • Proper error handling
  • Empty input handling
  • XSS protection
  • Configurable tag support

Installation

go get github.com/dracory/base/bbcode

Usage

package main

import (
    "fmt"
    "github.com/dracory/base/bbcode"
)

func main() {
    // Example BBCode text
    bbcodeText := `[b]Hello World[/b]
    
This is a [i]formatted[/i] text.
    
[url=https://example.com]Click here[/url]
    
[list]
[*]List item 1
[*]List item 2
[/list]`

    // Convert BBCode to HTML
    html, err := bbcode.BBCodeToHtml(bbcodeText)
    if err != nil {
        fmt.Printf("Error converting BBCode: %v\n", err)
        return
    }

    fmt.Println(html)
}

Configuration

The package will support the following configuration options:

  • Enable/disable specific BBCode tags
  • Custom tag definitions
  • HTML sanitization options
  • Output format (HTML5, XHTML)
  • Custom CSS class names

Error Handling

The BBCodeToHtml function will return an error if:

  • The BBCode conversion fails
  • The input text cannot be processed
  • Invalid BBCode syntax is encountered

Empty or whitespace-only input will be handled gracefully and return an empty string without error.

Security

The package will implement security measures:

  • XSS protection through HTML sanitization
  • URL validation for links and images
  • Configurable security policies
  • Safe default settings

License

This package is part of the dracory/base project and is licensed under the same terms. See the main README.md for license information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BbcodeToHtml

func BbcodeToHtml(input string) string

BbcodeToHtml takes a string written in BBCode and returns the HTML representation of it.

The function processes replacements in the order they are defined, ensuring that more specific patterns are processed before more general ones.

The function returns the HTML representation of the input string.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL