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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
//! The text construct elements: content set at the right edge of its line,
//! and a run of blocks set between rule lines, as nodes in the lowered tree.
//!
//! A construct element is a presentation element that mirrors one construct
//! of an output format, so that format-specific output is structured data in
//! the lowered tree rather than a string (see [backends, lowering, and
//! outputs](crate::guide::concepts_overview#backends-lowering-and-outputs)).
//! Plain text has two constructs that the shared presentation vocabulary
//! cannot express, since they depend on the width of the printed lines: a
//! part of a line pushed to the right edge, such as an equation's number, and
//! rule lines as wide as the content they enclose, such as the rules above
//! and under a document's title. This module holds the two elements that
//! mirror them, with their payloads:
//!
//! | element | payload | slots | printed as |
//! |---|---|---|---|
//! | [`FLUSH_RIGHT`] (`flm.pres.text.flush-right`) | [`FlushRightPayload`]: no data | one [`BODY_SLOT`](crate::stdlib::backends::pres::BODY_SLOT), inline content | its content on one line, ending at the last column of the line width where it fits there, otherwise [`FLUSH_RIGHT_GAP`] columns after what precedes it |
//! | [`RULED`] (`flm.pres.text.ruled`) | [`RuledPayload`]: whether a rule line stands above the body, and whether one stands under it | one [`BODY_SLOT`](crate::stdlib::backends::pres::BODY_SLOT), a run of blocks | its body on lines of its own, between rule lines as wide as the widest printed line of the body |
//!
//! The [text emitter](mod@super::emit) prints them with the layout engine's
//! constructors [`DocBuf::flush_right`](crate::layout::DocBuf::flush_right)
//! and [`DocBuf::ruled`](crate::layout::DocBuf::ruled); its module
//! documentation states what each prints in full.
//!
//! The `text` feature ([`super::TextBackend`]), which registers the text
//! backend, registers both elements through [`register`], and the text
//! backend writes them natively ([`native_elements`](super::native_elements)).
//! They are **not** part of the shared presentation vocabulary
//! ([`ALL`](crate::stdlib::backends::pres::ALL)): a backend that is not the
//! text backend cannot write them, and a lowering rule that stages one (builds
//! a node of it into the lowered tree; see
//! [`Lowerer`](crate::core::lowering::Lowerer)) is a rule for the text
//! backend. A feature that stages one without registering the `text` feature
//! itself declares it through a peer declaration
//! ([`PeerName`](crate::core::registry::PeerName),
//! [`FeatureBuilder::peer_element`](crate::core::registry::FeatureBuilder::peer_element)).
//!
//! # Projections
//!
//! Each payload implements [`PresPayload`] with a self-contained projection
//! (the value written when a lowered tree is serialized,
//! [`crate::dump::session`]) and has a registered reader that rebuilds the
//! payload from it ([`payload_readers`]). The projections are: `flush-right`:
//! `{}`; `ruled`: `{above, below}`, two booleans, an absent or null key read
//! as `false`.
use Arc;
use ;
use crate;
use cratePayloadReaders;
use crate;
use crate;
/// `flm.pres.text.flush-right` — inline content set at the right edge of its
/// line.
pub const FLUSH_RIGHT: &str = "flm.pres.text.flush-right";
/// `flm.pres.text.ruled` — a run of blocks set between rule lines as wide as
/// its widest printed line.
pub const RULED: &str = "flm.pres.text.ruled";
/// The two construct elements of the text backend, in the order of the
/// module documentation's table.
pub const ALL: = ;
/// The columns between the content of a [`FLUSH_RIGHT`] node and what
/// precedes it on its line, where the content does not fit at the right edge
/// of the line or the line has no width: four.
pub const FLUSH_RIGHT_GAP: u16 = 4;
/// The payload of `flm.pres.text.flush-right`: it holds no data. The node's
/// content, in its body slot, is what is set at the right edge.
;
/// The payload of `flm.pres.text.ruled`: where the rule lines stand around
/// the node's body.
///
/// Each rule line is the character of a heading at the root level
/// ([`TextRenderOptions::heading_rules`](super::TextRenderOptions::heading_rules))
/// repeated to the width of the widest line the body prints; a node with
/// neither rule prints its body alone.
///
/// # Examples
///
/// ```
/// use flm_core::lang::PresPayload;
/// use flm_core::stdlib::backends::text::construct::RuledPayload;
///
/// let both = RuledPayload { above: true, below: true };
/// assert_eq!(RuledPayload::from_projection(&both.project()).unwrap(), both);
/// ```
/// Returns the payload readers of the two construct elements: what a reading
/// session ([`reader_with`](crate::dump::session::reader_with)) needs, beside
/// the shared vocabulary's own
/// ([`payload_readers`](crate::stdlib::backends::pres::payload_readers)), to
/// read a stored lowered tree of the text backend back into typed payloads.
///
/// # Examples
///
/// ```
/// use flm_core::stdlib::backends::text::construct::{ALL, payload_readers};
///
/// let readers = payload_readers();
/// assert_eq!(readers.len(), ALL.len());
/// assert!(ALL.iter().all(|name| readers.elements().any(|element| element.as_str() == *name)));
/// ```
/// Registers the construct elements `flm.pres.text.flush-right` and
/// `flm.pres.text.ruled` with their payload types. The `text` feature
/// ([`super::TextBackend`]) calls this from its own registration; a second
/// registration in one registry declares the elements twice and fails the
/// build.
///
/// # Errors
///
/// Returns the [`BuildError`] the feature builder raises for a presentation
/// element already declared in this registry.