pukram-formatting

Crates.iopukram-formatting
lib.rspukram-formatting
version0.2.1
created_at2023-08-06 15:21:44.270725+00
updated_at2025-03-15 17:54:11.855402+00
descriptionA type to represent the formatting of the pukram markup language
homepage
repositoryhttps://gitlab.com/porky11/pukram-formatting
max_upload_size
id937216
size9,864
Fabio Krapohl (porky11)

documentation

https://docs.rs/pukram-formatting

README

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.

Commit count: 25

cargo fmt