Writing a Battery
Batteries are optional feature-gated packs built only on the public core
API: the same surface external users get. The contract (from
twrite_core::batteries):
- Create
batteries/<name>.rs(promote tobatteries/<name>/mod.rswhen it outgrows one file) with a fixed template:Config(plainClonedata +Default),Highlighter(new+with_config),Hook(new+with_config). Hook-only batteries omit the highlighter. - Declare the feature in
twrite-core/Cargo.toml(<name> = [...], withdep:<parser-crate>only if the battery needs a parser dependency). - Register the one-line path shim in the crate root so the public path stays
twrite_core::<name>regardless of file layout. - Re-export from the
twritefacade astwrite::<name>behind the same feature name, so users writetwrite = { features = ["<name>"] }. - Add colocated unit tests in the battery module and an
examples/<name>.rsdemo (withrequired-featuresonly if the demo needs the battery).
Further rules: batteries emit only existing HighlightTag variants (never
add new ones per battery) and never require twrite-gpui-side code; they
wire up via set_highlighter / add_hook, as demonstrated by
examples/vim.rs.
Markdown (twrite_core::markdown, re-exported as twrite::markdown) is the
reference implementation: highlighter, MarkdownHook (shortcuts, lists,
tables, task toggles), and MarkdownConfig toggles.