Giter VIP home page Giter VIP logo

bbclash's Introduction

BBClash

Crates.io Documentation Crates.io

A robust, opinionated, performance-focused BBCode to HTML parser and compiler.

What is 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.

Note: currently requires Rust Nightly. Relevant issue: 54727

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>");

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 and empty elements 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>");

assert_eq!(bbcode_to_html("[quote][/quote]"), 
		"");

Ugly uses the bbcode_to_html_ugly function, and leaves improperly formatted BBCode tags and empty elements 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>");

assert_eq!(bbcode_to_html_ugly("[quote][/quote]"), 
		"<blockquote></blockquote>");

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.

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

License

This version of BBClash is licensed under the terms of the MIT license.

bbclash's People

Contributors

endahallahan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.