Skip to main content

format_source

Function format_source 

Source
pub fn format_source(source: &str) -> String
Expand description

Format a Beancount source file in opinionated canonical form.

Reparses internally — callers that already have a CST in hand and want to avoid the double-parse can use format_node.

Returns canonical text; output always ends with exactly one trailing newline (even for an empty file, where the output is just "\n").

Line-ending normalization runs BEFORE parsing. The lexer does not treat bare \r as a line terminator, so a classic- Mac-authored directive\r…\rdirective\r would otherwise parse as a single broken directive and the rest of the user’s ledger would be silently dropped. We normalize \r\n and bare \r to \n first, then parse — matching the canonical-form promise that line endings are LF-only on output.