Crate pikru

Crate pikru 

Source
Expand description

§pikru

crates.io docs.rs MIT/Apache 2.0

A Rust implementation of pikchr, a PIC-like diagram markup language for creating technical diagrams that generates SVG.

§Usage

let svg = pikru::pikchr(r#"box "Hello" arrow box "World""#).unwrap();
assert!(svg.contains("<svg"));

§Light/Dark Mode

Enable CSS variables for automatic light/dark theming:

use pikru::{pikchr_with_options, RenderOptions};

let options = RenderOptions { css_variables: true };
let svg = pikchr_with_options(r#"box "Hello""#, &options).unwrap();
assert!(svg.contains("light-dark("));

The generated SVG includes a <style> block with CSS variables using light-dark(), so colors automatically adapt to the user’s color scheme.

§Development

§Testing

The test suite validates output against the original C implementation:

cargo test                     # Run all tests
cargo xtask compare-html       # Generate visual comparison HTML
cargo xtask generate-pngs      # Convert SVGs to PNGs for debugging

See comparison.html for a side-by-side visual comparison of C vs Rust output.

§Pre-commit Hooks

./hooks/install.sh

§Attribution

pikru is a direct Rust port of:

  • pikchr by D. Richard Hipp - The original C implementation, released under the 0-clause BSD license. The C source is vendored in vendor/pikchr-c/ for reference.

Also referenced during development:

§Continuous Integration

Our CI runs on Depot hosted runners — huge thanks to Depot for sponsoring the compute that keeps the pikru test suite flying.

§Sponsors

Thanks to all individual sponsors:

GitHub Sponsors Patreon

…along with corporate sponsors:

AWS Zed Depot

§License

Licensed under either of:

at your option.

Re-exports§

pub use render::RenderOptions;

Modules§

ast
Abstract Syntax Tree types for pikchr
errors
Error types with rich diagnostics using miette
macros
Macro expansion for pikchr
parse
Parse pest pairs into AST nodes
render
SVG rendering for pikchr diagrams
types
Strongly-typed numeric primitives for pikru (zero-cost newtypes).

Macros§

debug

Structs§

PikchrParser

Enums§

Rule

Functions§

pikchr
Render pikchr source to SVG.
pikchr_with_options
Render pikchr source to SVG with custom options.