6 stable releases

2.2.0 Jan 15, 2026
2.1.2 Jan 15, 2026
2.0.0 Jan 14, 2026
1.0.0 Jan 14, 2026

#3 in #bbcode


Used in 2 crates (via outstanding)

MIT license

54KB
1K SLoC

BBCode-style tag parser for terminal styling.

This crate provides a parser for [tag]content[/tag] style markup, designed for terminal output styling. It handles nested tags correctly and supports multiple output modes.

Example

use outstanding_bbparser::{BBParser, TagTransform};
use console::Style;
use std::collections::HashMap;

let mut styles = HashMap::new();
styles.insert("bold".to_string(), Style::new().bold());
styles.insert("red".to_string(), Style::new().red());

// Apply ANSI codes
let parser = BBParser::new(styles.clone(), TagTransform::Apply);
let output = parser.parse("[bold]hello[/bold]");
// output contains ANSI escape codes for bold

// Strip tags (plain text)
let parser = BBParser::new(styles.clone(), TagTransform::Remove);
let output = parser.parse("[bold]hello[/bold]");
assert_eq!(output, "hello");

// Keep tags visible (debug mode)
let parser = BBParser::new(styles, TagTransform::Keep);
let output = parser.parse("[bold]hello[/bold]");
assert_eq!(output, "[bold]hello[/bold]");

Unknown Tag Handling

Tags not found in the styles map can be handled in two ways:

For validation, use BBParser::validate to check for unknown tags before parsing.

Tag Name Syntax

Tag names follow CSS identifier rules:

  • Start with a letter (a-z) or underscore (_)
  • Followed by letters, digits (0-9), underscores, or hyphens (-)
  • Cannot start with a digit or hyphen followed by digit
  • Case-sensitive (lowercase recommended)

Pattern: [a-z_][a-z0-9_-]*

Dependencies

~2–12MB
~76K SLoC