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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//! Markdown formatter.
//!
//! The structural emit is identity: [`document::format_document`]
//! returns the source bytes after the canonicalise pass and the
//! wrap pass have rewritten the buffer per [`crate::FmtOptions`].
pub
pub
pub
pub
pub
use crate::;
/// Apply the trailing-newline policy at the document boundary.
///
/// `Preserve` (the default) shapes the output to match the source's
/// trailing-newline run: one terminating `\n` if the source had any,
/// none otherwise. This is the only policy that preserves event
/// stability on inputs ending in an indented or fenced code block, where
/// any LF the post-pass introduces lands inside the code body on
/// re-parse.
/// See `docs/architecture/pulldown-model.md` §2 for the trailing-blank-
/// line rule this post-pass exists to defend against.
///
/// The "did the source end with `\n`?" probe ignores trailing
/// horizontal whitespace (`' '` / `'\t'`). Pulldown treats a final
/// line of only spaces/tabs as a stripped trailing blank line: the
/// effective document ends one `\n` earlier than the byte count
/// suggests. Without the trim, source `\t|\n\t` (indented code,
/// content `|\n`, trailing tab-only blank line) reads as
/// "no trailing `\n`", so the boundary strips the code block's
/// content `\n` and the re-parse sees content `|` instead of `|\n`
/// (`fuzz_indented_code_trailing_ws_drop.in`).
///
/// `Strip` drops every trailing `\n`. `Ensure` forces exactly one
/// trailing `\n`.
pub
/// Count of trailing `\n` bytes after first trimming any horizontal
/// whitespace (`' '` / `'\t'`) suffix. The trim matches pulldown's
/// effective-trailing-blank-line rule (CM §4.4 / 4.6): a final line of
/// only spaces/tabs is stripped, so the document's effective
/// trailing-LF count is the LF run immediately before that trailing
/// whitespace.
/// Normalise every `\r\n` and lone `\r` in `out` to `\n`.
///
/// `format_document` operates on `Source::canonical()` bytes, which
/// are already LF-only. This pass is cheap belt-and-braces
/// (`.contains('\r')` early-out; zero allocation when clean) for
/// callers that bypass the canonicalisation.
pub
/// Apply the end-of-line policy to a freshly-rendered `String`.
/// Caller invariant: `out` contains only `\n` line terminators
/// (enforced by [`normalize_line_endings_lf`] inside
/// `format_document`). Converting to CRLF is then a straightforward
/// replace; `Keep` adopts the source's first newline style.
pub