#text-formatting #markup-language #markup #formatting #text #pukram

pukram-formatting

A type to represent the formatting of the pukram markup language

3 unstable releases

Uses new Rust 2024

new 0.2.1 Mar 15, 2025
0.2.0 Sep 19, 2024
0.1.0 Aug 6, 2023

#11 in #text-formatting


Used in 2 crates

MIT/Apache

9KB
65 lines

Pukram formatting

crates.io docs.rs [License](LICENSE-MIT OR LICENSE-APACHE)

A Rust library for combining text formatting styles using bitwise operations. Designed for the pukram markup language.

Features

  • Several supported formattings:
    • *bold*
    • /italic/
    • `monospace`
    • ^superscript^
    • |subscript|
    • _underscore_
    • ~strikethrough~
  • Bitwise operator support (|, &, ^, etc.)
  • Toggle formats with marker characters

Usage

Basic Formatting

use pukram_formatting::Formatting;

// Combine formats with bitwise OR
let bold_underscore = Formatting::BOLD | Formatting::UNDERSCORE;
let small = Formatting::TOP | Formatting::BOTTOM;

Format Checking

let mut fmt = Formatting::BOLD | Formatting::ITALIC;

assert!(fmt.is_bold());
assert!(fmt.contains(Formatting::ITALIC));
assert!(!fmt.is_strikethrough());

// Remove bold formatting
fmt ^= Formatting::BOLD;
assert!(!fmt.is_bold());

Character-Activated Formatting

let mut fmt = Formatting::default();

// Toggle formats using marker characters
fmt.apply('*');  // Toggle bold
fmt.apply('/');  // Toggle italic
fmt.apply('`');  // Toggle monospace

// Invalid characters are ignored
assert!(!fmt.apply('x'));  // Returns false

When parsing a text to add formatting, you would usually use this.

Combined Formatting

// Create complex combinations
let warning = Formatting::BOLD | Formatting::UNDERSCORE | Formatting::STRIKETHROUGH;

// Mix with bitwise operations
let modified_warning = warning ^ (Formatting::UNDERSCORE | Formatting::BOLD);

Documentation

Full API reference available at docs.rs/pukram-formatting.

Dependencies

~275–740KB
~17K SLoC