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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
//! Output regions: the named parts an output's entry artifact is made of, the
//! table in which a backend writes them, and a backend's statement that its
//! output is made of them.
//!
//! An output region is one named part of an output's entry artifact (the
//! document's content, each [piece](crate::core::piece) placed beside it, and
//! on HTML the stylesheets, the scripts, the title and the language), which
//! the backend writes once into the table `flm.output.<backend>.regions`
//! ([`Regions`]). The entry artifact is the artifact that represents the
//! output as a whole: the HTML page, the printed text, the recomposed LaTeX
//! document ([`ArtifactSet`]).
//!
//! The backend's final stage assembles the entry artifact from those regions,
//! in a layout of the backend's own, and publishes the result as the output's
//! artifact set. A host may instead assemble the same regions through a
//! template of its own, with a stage that the plan schedules in place of the
//! backend's final stage ([output regions and the final
//! stage](crate::guide::concepts_overview#output-regions-and-the-final-stage)).
//! Either way the regions are computed once. The [`Regions`] table also states
//! what the entry artifact is (its identity, its media type and the artifacts
//! it refers to), so that every assembler makes the same artifact from one
//! statement.
//!
//! This module holds the region names (below), one region ([`Region`]), the
//! regions of one output ([`Regions`]), the function that computes a piece's
//! plain words ([`piece_words`]), and a backend's statement that an output is
//! made of regions ([`RegionsOutput`]).
//!
//! # The region names
//!
//! | Name | What the region holds | Backends |
//! |---|---|---|
//! | [`CONTENT`] | the document's content: every tree in document order; a tree placed inside another tree is written where it is placed | every backend (the text backend writes its pieces inside this region too) |
//! | a piece's name | that piece, as the backend writes it | HTML, recomposed LaTeX |
//! | [`STYLES`] | the stylesheets the document requires, one part per HTML element (`<style>` or `<link>`) | HTML |
//! | [`SCRIPTS`] | the scripts the document requires, one part per `<script>` element | HTML |
//! | [`TITLE`] | the words of the page's title: the document's title, else the title the HTML render options ([`HtmlRenderOptions`](crate::stdlib::backends::html::HtmlRenderOptions)) give | HTML |
//! | [`LANG`] | the page's language tag, when the HTML render options give a language; absent otherwise | HTML |
//! | [`STYLE_PACKAGE`] | the package name of the style file, when the output has a style file | recomposed LaTeX |
//!
//! # Which outputs are made of regions
//!
//! A backend whose output is made of regions states it by contributing a
//! [`RegionsOutput`] to the service slot
//! [`flm.output.regions`](crate::stdlib::backends::lowering::REGIONS_SLOT):
//! the output, its backend, the table of its regions, the tables of the files
//! written beside its entry artifact, and the capability its final stage
//! provides. A stage that assembles the regions another way, such as a
//! host's template stage, reads that service slot to learn which outputs it can
//! serve. It
//! therefore serves exactly the outputs of the backends the registry holds.
//!
//! # Parts
//!
//! A region is a list of **parts**, each a text the backend wrote in its
//! output format (HTML, LaTeX or plain text). The HTML backend's final stage places each part of a
//! region on a line of its own, at the indentation of the place where the
//! region goes. A template places the region's [`text`](Region::text): its
//! parts joined by line breaks. A region that is one text has one part.
use NodeTree;
use SerialValue;
use crate;
use crate;
use cratePiecePlace;
use crateFlm;
use crate;
/// The name of the output region holding the document's content, `content`.
pub const CONTENT: &str = "content";
/// The name of the output region holding the stylesheets an HTML page loads,
/// `styles`.
pub const STYLES: &str = "styles";
/// The name of the output region holding the scripts an HTML page loads,
/// `scripts`.
pub const SCRIPTS: &str = "scripts";
/// The name of the output region holding the words of an HTML page's title,
/// `title`.
///
/// The words are those of the document's title piece when the render places
/// that piece and its words are not empty, else the title the HTML render
/// options give
/// ([`HtmlRenderOptions`](crate::stdlib::backends::html::HtmlRenderOptions)).
/// The region's [`words`](Region::words) are the plain text, and its one part
/// is that text escaped as HTML text.
pub const TITLE: &str = "title";
/// The name of the output region holding an HTML page's language tag, `lang`.
///
/// The region is present only when the HTML render options
/// ([`HtmlRenderOptions`](crate::stdlib::backends::html::HtmlRenderOptions))
/// give a language. Its [`words`](Region::words) are the tag, and its one
/// part is the tag escaped as the value of an HTML attribute.
pub const LANG: &str = "lang";
/// The name of the output region holding the package name of the recomposed
/// LaTeX's style file, `style-package`: the name with which a LaTeX document
/// loads the style file through `\usepackage`.
pub const STYLE_PACKAGE: &str = "style-package";
/// One output region: its name, whether it is a piece, its parts, and the
/// plain words of a piece or of the HTML title and language.
///
/// Build one with [`Region::new`], [`Region::with_words`] or
/// [`Region::piece`]. A backend's regions stage pushes the regions of its
/// output into a [`Regions`] table.
/// Returns the words of a piece whose lowered tree is `tree`, as its region
/// carries them ([`Region::words`]): the tree's plain text
/// ([`plain_text`](crate::lang::text::plain_text)), with every run of white
/// space replaced by one space and none at either end.
///
/// The HTML and recomposed LaTeX backends compute a piece's words with this
/// function, so that both give the same words for the same piece.
/// The output regions of one output, and what the entry artifact assembled
/// from them is: the value of the table `flm.output.<backend>.regions`, which
/// a backend's regions stage writes once per run.
///
/// The backend's final stage, or a host's template stage, reads it to make
/// the entry artifact; see the [module documentation](self).
/// A regions output: a backend's statement that its output is made of output
/// regions (which table holds them and which capability its final stage
/// provides), contributed to the service slot `flm.output.regions` so that a
/// host's own assembler can read it.
///
/// A backend contributes one per such output to the service slot
/// [`flm.output.regions`](crate::stdlib::backends::lowering::REGIONS_SLOT);
/// see the [module documentation](self#which-outputs-are-made-of-regions).