Crates.io | pukram-formatting |
lib.rs | pukram-formatting |
version | 0.2.1 |
created_at | 2023-08-06 15:21:44.270725+00 |
updated_at | 2025-03-15 17:54:11.855402+00 |
description | A type to represent the formatting of the pukram markup language |
homepage | |
repository | https://gitlab.com/porky11/pukram-formatting |
max_upload_size | |
id | 937216 |
size | 9,864 |
[
](LICENSE-MIT OR LICENSE-APACHE)
A Rust library for combining text formatting styles using bitwise operations. Designed for the pukram markup language.
*bold*
/italic/
`monospace`
^superscript^
|subscript|
_underscore_
~strikethrough~
|
, &
, ^
, etc.)use pukram_formatting::Formatting;
// Combine formats with bitwise OR
let bold_underscore = Formatting::BOLD | Formatting::UNDERSCORE;
let small = Formatting::TOP | Formatting::BOTTOM;
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());
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.
// Create complex combinations
let warning = Formatting::BOLD | Formatting::UNDERSCORE | Formatting::STRIKETHROUGH;
// Mix with bitwise operations
let modified_warning = warning ^ (Formatting::UNDERSCORE | Formatting::BOLD);
Full API reference available at docs.rs/pukram-formatting.