[][src]Crate bbclash

BBClash is the open-source version of the BBCode compiler being built for Penclash. Unlike most implementations, BBClash is not RegEx-based. It functions like a compiler, tokenizing, lexing, and then constructing compliant HTML from an AST-like object. This makes it robust and good at handling even improperly-formatted input.

Our BBCode specification can be found here.

General Usage:

use bbclash::bbcode_to_html;

assert_eq!(bbcode_to_html("I'm [i]italic[/i] and [b]bold![/b]"), 
		"<p>I&#x27m <i>italic</i> and <b>bold!</b></p>");

BBClash also comes ready out-of-the-box for use as WASM or with other languages via C bindings.

Pretty and Ugly Output

BBClash has two main modes of operation: pretty and ugly. Pretty output uses the bbcode_to_html function, and excludes improperly formatted bbcode from the final output:

use bbclash::bbcode_to_html;

assert_eq!(bbcode_to_html("I'm [colour]missing an argument![/colour]"), 
		"<p>I&#x27m missing an argument!</p>");

Ugly uses the bbcode_to_html_ugly function, and leaves improperly formatted BBCode tags in the final output as written:

use bbclash::bbcode_to_html_ugly;

assert_eq!(bbcode_to_html_ugly("I'm [colour]missing an argument![/colour]"), 
		"<p>I&#x27m [colour]missing an argument![/colour]</p>");

Note that neither mode arbitrarily strips any text in square brackets. this only affects improperly-written BBCode tags; [non tags] will not be affected.

Custom Usage:

Because this package was built for an existing application, and because it is performance-focused, BBClash's BBCode implementation is entirely hard-coded. Because of this, it is reccommended that you download a local copy and modify it to suit your needs. Note: currently requires Rust Nightly to build. Relevant issue: 54727

Building is as simple as running $ cargo build. Tests and benchmarks can be run with $ cargo test and $ cargo bench, respectively.

Structs

ASTElement

A single element of a BBCode AST.

BBCodeLexer

Struct for lexing BBCode Instructions into an ASTElement tree.

BBCodeTokenizer

Struct for BBCode tokenization.

HTMLConstructor

Struct for generation of HTML strings.

Enums

Argument

Types of argument for Instructions.

GroupType

Types of ASTElement.

Instruction

A single Instruction output by the tokenizer.

Functions

bbcode_to_html

Generates a string of HTML from an &str of BBCode. This function produces pretty output, meaning that any eroneously written BBCode encountered will be removed from the final output.

bbcode_to_html_ugly

Generates a string of HTML from an &str of BBCode. This function produces ugly output, meaning that any eroneously written BBCode encountered will be included in the final output.