Skip to main content

Crate snapper_fmt

Crate snapper_fmt 

Source
Expand description

§snapper

Semantic line break formatter for prose documents. Reformats text so each sentence occupies its own line, producing minimal git diffs when collaborating on papers and documentation.

The crate is published as snapper-fmt on crates.io. Installers ship two CLI names for the same program: snapper and snapper-fmt (the latter avoids colliding with openSUSE’s Btrfs snapshot tool of the same name).

§Supported formats

  • Org-mode: drawers, tables, keywords preserved; #+BEGIN_SRC is Region::Code (comment reflow via [code.<lang>], optional formatters)
  • LaTeX: preamble and math preserved; minted / lstlisting are code regions
  • Markdown: front matter and headings preserved; fenced blocks are code regions
  • RST: directives and literals preserved; .. code-block:: is a code region
  • Plaintext: everything treated as prose

§Library usage

use snapper_fmt::{format_text, FormatConfig};
use snapper_fmt::format::Format;

let input = "Hello world. This is a test. Another sentence.";
let config = FormatConfig {
    format: Format::Plaintext,
    ..Default::default()
};
let output = format_text(input, &config).unwrap();
assert_eq!(output, "Hello world.\nThis is a test.\nAnother sentence.");

Modules§

abbreviations
check
Line-level --check diagnostics: fused, wrap, and long.
cli
code_block
Comment-aware reflow inside a Region::Code.
config
diff
files
format
Document format detection and representation.
git_diff
init
lsp
mcp
MCP (Model Context Protocol) server for snapper.
oracle
Format-local render oracle used as a fail-closed backstop.
output
parser
reflow
sdiff
sentence
watch

Structs§

FormatConfig
Configuration for the formatting pipeline.
InvalidUtf8Error
Typed error for invalid UTF-8 input. Branch with error.downcast_ref.
PandocCannotSplice
Pandoc’s AST has no source offsets, so it cannot splice into original bytes. format_text refuses rather than reconstruct.

Functions§

build_splitter
Build the appropriate sentence splitter from config.
format_bytes
Format raw bytes. Invalid UTF-8 is a hard error (InvalidUtf8Error).
format_range
Format only lines within a range (1-indexed, inclusive). Lines outside the range pass through unchanged.
format_text
Format text with semantic line breaks.
format_text_with_splitter
Format text using a pre-constructed splitter (avoids reloading models per file).
run_fixpoint
Run step until the output is a byte fixpoint or the cap is hit.