Skip to main content

rumdl_lib/code_block_tools/
mod.rs

1//! Per-language code block linting and formatting using external tools.
2//!
3//! This module provides infrastructure for running external formatters and linters
4//! on fenced code blocks in markdown files, based on their language tags.
5//!
6//! # Overview
7//!
8//! When enabled, rumdl can process code blocks using external tools:
9//! - **Lint mode** (`rumdl check`): Run linters and report diagnostics
10//! - **Format mode** (`rumdl check --fix` / `rumdl fmt`): Run formatters and update content
11//!
12//! # Configuration
13//!
14//! Code block tools are disabled by default. Enable and configure in `.rumdl.toml`:
15//!
16//! ```toml
17//! [code-block-tools]
18//! enabled = true
19//! normalize-language = "linguist"  # Resolve aliases like "py" -> "python"
20//! on-error = "fail"                # or "skip" / "warn"
21//! timeout = 30000                  # ms per tool
22//!
23//! [code-block-tools.languages.python]
24//! lint = ["ruff:check"]
25//! format = ["ruff:format"]
26//!
27//! [code-block-tools.languages.shell]
28//! lint = ["shellcheck"]
29//! format = ["shfmt"]
30//!
31//! [code-block-tools.language-aliases]
32//! py = "python"
33//! bash = "shell"
34//! ```
35//!
36//! # Built-in Tools
37//!
38//! Common tools are pre-configured:
39//! - `ruff:check`, `ruff:format` - Python
40//! - `prettier`, `prettier:json`, etc. - JavaScript, JSON, YAML, etc.
41//! - `shellcheck`, `shfmt` - Shell scripts
42//! - `rustfmt` - Rust
43//! - `gofmt`, `goimports` - Go
44//! - And many more (see [`registry`] module)
45//!
46//! # Custom Tools
47//!
48//! Define custom tools in configuration:
49//!
50//! ```toml
51//! [code-block-tools.tools.my-formatter]
52//! command = ["my-tool", "--format"]
53//! stdin = true
54//! stdout = true
55//! ```
56//!
57//! # Language Resolution
58//!
59//! With `normalize-language = "linguist"` (default), common aliases are resolved:
60//! - `py`, `python3` → `python`
61//! - `bash`, `sh`, `zsh` → `shell`
62//! - `js`, `node` → `javascript`
63//!
64//! See [`linguist`] module for the full list.
65
66pub mod config;
67pub mod executor;
68pub mod linguist;
69pub mod processor;
70pub mod registry;
71
72pub use config::{CodeBlockToolsConfig, LanguageToolConfig, NormalizeLanguage, OnError, OnMissing, ToolDefinition};
73pub use executor::{ExecutorError, ToolExecutor, ToolOutput};
74pub use linguist::LinguistResolver;
75pub use processor::{
76    CodeBlockDiagnostic, CodeBlockResult, CodeBlockToolProcessor, DiagnosticSeverity, FencedCodeBlockInfo,
77    FormatOutput, ProcessorError, RUMDL_BUILTIN_TOOL,
78};
79pub use registry::ToolRegistry;