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; the binary it installs is called snapper.

§Supported formats

  • Org-mode: blocks, drawers, tables, keywords preserved
  • LaTeX: preamble, math, environments, comments preserved
  • Markdown: code blocks, front matter, headings preserved
  • 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,
    max_width: 0,
    use_neural: false,
    neural_lang: "en".to_string(),
    neural_model_path: None,
    extra_abbreviations: vec![],
    use_pandoc: false,
    pandoc_format: None,
};
let output = format_text(input, &config).unwrap();
assert_eq!(output, "Hello world.\nThis is a test.\nAnother sentence.");

Modules§

abbreviations
cli
config
diff
files
format
git_diff
init
lsp
output
parser
reflow
sdiff
sentence
watch

Structs§

FormatConfig
Configuration for the formatting pipeline.

Functions§

build_splitter
Build the appropriate sentence splitter from config.
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).