1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! File helpers for rewriting Markdown documents.
//!
//! Rewrites replace the target through a temporary file in the same directory
//! and a rename, so a failure part-way through leaves the original file intact
//! rather than truncated. Every filesystem operation runs through a `cap_std`
//! directory capability: [`rewrite`] and [`rewrite_no_wrap`] open one for the
//! target's parent, and the CLI passes the capability it already holds.
//!
//! The module is split by concern, and each part is a child module here:
//!
//! - `document` owns the document boundary — the byte-order mark a document may begin with, held
//! together with the terminator its output is written with, so the mark is split off before
//! formatting and restored afterwards.
//! - `line_endings` owns the policy — which terminator an output document is written with, and how
//! the majority style is counted out of the input.
//! - `replace` owns the replacement entry points, including the boundary that selects a document's
//! style and reports the decision it made.
//! - `swap` owns the temporary file and the rename that make a replacement atomic.
//!
//! [`detect_line_ending`], [`count_line_endings`], and [`serialize_lines`] are
//! pure queries and emit nothing. The rewrite helpers report the decision, with
//! the counts behind it, at `debug` level, so a caller can trace why a file was
//! rewritten with the endings it has without the query itself becoming
//! side-effecting.
//!
//! The rationale, the rejected alternatives and the known limitations are
//! recorded in `docs/adrs/0007-line-ending-detection.md`.
pub use SourceDocument;
pub use ;
/// Re-exposes the internals the unit tests drive directly, so that a test
/// module reaches them without naming the child module they live in.
use ;
pub use ;
use ;