Expand description
§R3BL Build Infrastructure
Build tools and utilities designed for R3BL projects, but usable in any Rust project.
§cargo-rustdoc-fmt
A cargo subcommand that formats markdown tables and converts inline links to
reference-style links within Rust documentation comments (/// and //!).
§Features
- Table Formatting: Aligns markdown table columns for readability
- Link Conversion: Converts inline markdown links to reference-style links, keeping documentation cleaner
- Workspace Support: Process entire Rust workspaces or specific files
- Check Mode: Verify formatting without modifying files (useful for CI)
- Selective Formatting: Choose to format only tables, only links, or both
- Git Integration: Auto-detects changed files in git working tree
§Installation
From crates.io:
cargo install r3bl-build-infraOr from source (in a workspace containing this crate):
cargo install --path build-infra§Usage Examples
Format git-changed files (default - auto-detects staged/unstaged changes):
cargo rustdoc-fmtFormat entire workspace:
cargo rustdoc-fmt --workspaceFormat specific files:
cargo rustdoc-fmt src/lib.rs src/main.rsFormat a directory:
cargo rustdoc-fmt src/Check formatting without modifying (useful for CI):
cargo rustdoc-fmt --checkOnly format tables (skip link conversion):
cargo rustdoc-fmt --tables-onlyOnly convert links (skip table formatting):
cargo rustdoc-fmt --links-onlyVerbose output:
cargo rustdoc-fmt --verboseCombine options:
cargo rustdoc-fmt --check --verbose src/§What It Does
§Table Formatting
Markdown tables in rustdoc comments are reformatted with consistent column widths.
Before:
//! | A | B |
//! |---|---|
//! | Short | Very Long Text |After:
//! | A | B |
//! |-------|----------------|
//! | Short | Very Long Text |§Link Conversion
Inline markdown links are converted to reference-style links using the link text as the reference identifier, reducing visual clutter in documentation.
Before:
//! See [docs](https://example.com) and [Rust](https://rust-lang.org).After:
//! See [docs] and [Rust].
//!
//! [docs]: https://example.com
//! [Rust]: https://rust-lang.org§Git Integration
When run without arguments, cargo-rustdoc-fmt intelligently determines which files
to format:
- If there are staged/unstaged changes: Formats only those changed files
- If working tree is clean: Formats files from the most recent commit
- If not in a git repository: Formats the entire workspace
This makes it perfect for pre-commit hooks and development workflows.
§CI Integration
Add to your continuous integration pipeline to enforce formatting standards:
cargo rustdoc-fmt --checkExits with code 1 if formatting is needed, allowing CI to fail the build.
Example GitHub Actions step:
- name: Check rustdoc formatting
run: cargo rustdoc-fmt --check --verbose§Architecture
The project follows a multi-tool design pattern (similar to the cmdr/ crate).
Currently implements cargo-rustdoc-fmt, with support for adding additional
build tools in the future without refactoring.
Module structure:
src/lib.rs- Library rootsrc/bin/cargo-rustdoc-fmt.rs- Binary entry pointsrc/cargo_rustdoc_fmt/- Tool implementationcli_arg.rs- CLI argument parsingextractor.rs- Extract rustdoc blocks from sourcetable_formatter.rs- Format markdown tableslink_converter.rs- Convert inline to reference-style linksprocessor.rs- Orchestrate file processingir_event_types- Type definitionsui_str.rs- User-facing messages
src/common/- Shared utilitiesgit_utils.rs- Git integrationworkspace_utils.rs- Workspace discovery and file finding
§Implementation Notes
Currently uses pulldown-cmark for markdown parsing. This will be migrated to
r3bl_tui::md_parser once table support is added to that parser, achieving full
R3BL infrastructure dogfooding.
Re-exports§
pub use common::*;
Modules§
- cargo_
rustdoc_ fmt - Rust documentation formatting tools.
- common
- Shared utilities across all build tools.