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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
//! The `html` feature: registers the HTML backend, its render options, the
//! `html` output and the `html` workflow, and declares the four names the rest
//! of the library uses to refer to them.
//!
//! The `html` feature ([`FlmFeature`]),
//! implemented by [`HtmlBackend`] and obtained with [`feature()`], registers:
//!
//! - the construct element [`flm.pres.html.tag`](super::construct::TAG), one
//! HTML tag as a node of the lowered tree;
//! - the seven stylesheets and the formula renderer's script that the backend
//! ships, the definitions table `flm.html.definitions` and the stage that
//! writes it ([`super::defs`]);
//! - the tables the backend's stages write: the lowered trees
//! (`flm.lowered.html`), the HTML of each tree (`flm.output.html`), the page's
//! artifact set (`flm.output.html.document`) with its capability
//! [`flm.output.html.singlefile`](super::stages::SINGLEFILE), the artifact
//! table `flm.output.html.artifacts` that the final stage reads, the lowered
//! pieces (the document-level values a backend places beside the content,
//! such as the title; [`Piece`](crate::core::piece::Piece))
//! (`flm.lowered.html.pieces`), the HTML of each piece
//! (`flm.output.html.pieces`) and the regions (`flm.output.html.regions`);
//! - the stage that builds the lowered pieces ([`PiecesStage`] for the `html`
//! backend), the stage `flm.html.emit-pieces` and the regions stage
//! `flm.html.regions`;
//! - the backend's regions output
//! ([`RegionsOutput`]), contributed to
//! the service slot `flm.output.regions`, so that a host's own page assembler
//! can find the regions;
//! - the backend itself, with its native element set and its three stages
//! ([`super::stages::stages`]);
//! - the `html` output and the `html` workflow.
//!
//! The render options are [`HtmlRenderOptions`], declared with the feature's
//! settings under the feature name `html`, and
//! [`HtmlAllowedUrlSchemes`], the URL schemes the page may reference, which the
//! feature declares beside its settings so that only Rust code sets it ([who
//! decides which schemes are
//! allowed](super::address#who-decides-which-schemes-are-allowed)). The backend's name is the base of
//! the names of its stages (`flm.html.*`) and of its lowered-trees table
//! (`flm.lowered.html`). The identifiers of the conditions it reports
//! (`flm.html.*`) take the feature's name, [`FEATURE_NAME`], which is also
//! `html`.
//!
//! A future HTML output, such as a multi-file one, is meant to add a second
//! final stage to this backend rather than a backend of its own. A feature of
//! another crate whose lowering rule stages an HTML tag node (builds it into
//! the lowered tree; see [`Lowerer`](crate::core::lowering::Lowerer)) declares
//! the construct element through a peer declaration
//! ([`PeerName`](crate::core::registry::PeerName),
//! [`FeatureBuilder::peer_element`](crate::core::registry::FeatureBuilder::peer_element))
//! instead of depending on this feature.
//!
//! # The elements the backend writes natively
//!
//! The native set ([`native_elements`]) holds 29 elements: every element of the
//! [presentation vocabulary](crate::stdlib::backends::pres), the construct
//! element [`flm.pres.html.tag`](super::construct::TAG), and the six
//! [structural elements](crate::guide::concepts_overview#structural-elements)
//! of [`FLOW_THROUGH`] that the backend emits natively, without a lowering rule,
//! because they carry nothing an HTML page has to translate: `flm.text`,
//! `flm.group`, `flm.opaque-wrapper`, `flm.comment`, `flm.container` and
//! `flm.parbreak`.
//!
//! The native set holds **no element another feature owns**, and in
//! particular not the reference element `flm.ref`. The `refs` feature's own
//! lowering rule for `flm.ref` is therefore selected, and because that rule
//! reads the resolved references, the plan schedules the stage that resolves
//! them and, before it, the stage that computes the anchors. A heading then
//! reaches the emitter with the anchor that becomes its `id`. In a registry
//! without the `refs` feature, a heading carries no anchor and therefore no
//! `id`, as on every other backend.
//!
//! This backend needs the same [tree
//! state](crate::guide::concepts_overview#frozen-trees-and-computed-data) as the
//! text backend (blocks
//! structured, user definitions expanded), so one plan serves both, and a
//! request for the `text` and the `html` outputs together is one run. A
//! request for `html` and `latex-recomposed` together is refused, as one for
//! `text` and `latex-recomposed` is, because those backends need different
//! tree states.
//!
//! # What the `html` workflow demands
//!
//! The `html` [workflow](crate::core::registry::WorkflowDef) lists the `html`
//! output and also demands (asks the plan for a stage that provides;
//! [`PlanRequest::demand`](crate::core::plan::PlanRequest::demand)) the
//! [capability](crate::core::registry::CapabilityDef)
//! [`flm.validated`](crate::stdlib::VALIDATED), which the document's checks
//! provide together, so that every workflow runs the same checks over a
//! document. The `check` feature
//! ([`check_feature`](crate::stdlib::check_feature)) declares that
//! capability, so a registry that holds this backend must hold the `check`
//! feature too.
//!
//! See the [module documentation](super) for the backend as a whole.
use ;
use Arc;
use crateSettingsDecl;
use crateArtifactSet;
use crate;
use cratestructural;
use crate;
use crateBind;
use crateVALIDATED;
use crate;
use crate;
use cratepres;
use crateRegionsOutput;
use crateREGIONS_SLOT;
use HtmlAllowedUrlSchemes;
use construct;
use defs;
use ;
/// The feature's registered name, `html`. It is also the middle part of the
/// identifiers of the conditions this backend reports, `flm.html.*`, and the
/// name under which the feature's settings are declared.
pub const FEATURE_NAME: &str = "html";
/// The declaration of the feature's settings: the fields of
/// [`HtmlRenderOptions`] are its settings keys, bound to the render request,
/// and the key `run_in_stop` is marked as text in FLM markup
/// ([`Mark::Markup`](crate::core::settings::Mark::Markup)). See
/// [`crate::core::settings`].
/// The backend's name, `html`.
///
/// A lowering rule marked as the default on this backend refers to it by this
/// name, and the names of the backend's lowering stage (`flm.html.lower`) and
/// lowered-trees table (`flm.lowered.html`) are derived from it.
pub const BACKEND: &str = "html";
/// The `html` output's name.
///
/// It is spelled like the backend's name but is the name of an output: a
/// workflow lists it
/// ([`WorkflowDef::output`](crate::core::registry::WorkflowDef::output)), and a
/// host looks the output up by it
/// ([`FlmRegistry::output`](crate::core::registry::FlmRegistry::output)).
pub const OUTPUT: &str = "html";
/// The `html` workflow's name.
///
/// It is spelled like the backend's name but is the name of a workflow, the
/// argument [`Plan::for_workflow`](crate::core::plan::Plan::for_workflow)
/// takes.
pub const WORKFLOW: &str = "html";
/// The six [structural elements](crate::guide::concepts_overview#structural-elements)
/// the HTML backend emits natively, without a lowering rule, beside the
/// presentation vocabulary and the construct element: text, groups, opaque
/// wrappers, source comments, containers and paragraph breaks (see the [module
/// documentation](self)).
pub const FLOW_THROUGH: = ;
/// Returns the backend's native element set, the elements its emitter writes
/// without a lowering rule: every element of the presentation vocabulary
/// ([`pres::ALL`]), the construct element
/// [`flm.pres.html.tag`](super::construct::TAG), then the elements of
/// [`FLOW_THROUGH`], in that order (29 elements).
///
/// The set holds no element another feature owns; the [module
/// documentation](self#the-elements-the-backend-writes-natively) says why.
///
/// # Examples
///
/// ```
/// use flm_core::stdlib::backends::html::{FLOW_THROUGH, TAG, native_elements};
/// use flm_core::stdlib::backends::pres;
///
/// let native = native_elements();
/// assert_eq!(native.len(), pres::ALL.len() + 1 + FLOW_THROUGH.len());
/// assert_eq!(native.len(), 29);
/// assert!(native.iter().any(|element| element.as_str() == TAG));
/// // No element another feature owns: a reference is lowered by the `refs`
/// // feature's own rule, so the plan schedules the stage computing the anchors.
/// assert!(!native.iter().any(|element| element.as_str() == "flm.ref"));
/// ```
// --- the render options -------------------------------------------------------------------
/// The delivery of a style or script definition: how the definition reaches
/// the page.
///
/// A style or script definition ([`StyleDef`](crate::core::registry::StyleDef),
/// [`ScriptDef`](crate::core::registry::ScriptDef)) is a stylesheet or a script
/// that a feature's output depends on, recorded in the registry under an
/// identifier; the backend that writes the output decides its *delivery*:
/// written into the output, loaded from an address, or left to the host (see
/// [style and script
/// definitions](crate::guide::concepts_overview#style-and-script-definitions)).
///
/// This type has two uses:
///
/// - a host gives one per definition identifier in the render option
/// [`HtmlRenderOptions::definitions`], in place of the definition's declared
/// content;
/// - each row of the definitions table records the delivery the definition
/// ended up with
/// ([`ResolvedDefinition::delivery`](super::defs::ResolvedDefinition::delivery)).
///
/// An entry of the option replaces the declared content and never changes
/// *what* the document requires: the definition is still listed in the
/// definitions table, so a host or a bundler reading that table learns that the
/// document needs it.
///
/// A delivery is an ordered list of parts, as a definition's declared content
/// is, and an entry of the option replaces the whole list. The formula
/// renderer's definition, for example, holds a configuration and then the
/// address of the program: a host that wants its own address writes both
/// parts, because a page without the configuration renders mathematics
/// wrongly.
/// The render options of the HTML backend: the page's title and language, the
/// source-position attribute, the stop after a run-in heading, how stylesheets
/// and scripts are delivered, the stylesheets and scripts the host adds to the
/// page, how headings are tagged, and the heading level written as `<h1>`.
///
/// The option type is declared with [`Bind::Render`], so its values come from
/// the render request rather than from the document (see [settings, options and
/// configuration](crate::guide::concepts_overview#settings-options-and-configuration)).
/// The values are set on the plan request
/// ([`PlanRequest::render_options`](crate::core::plan::PlanRequest::render_options())),
/// so two runs asking for different titles use two plans. The emit stages
/// (`flm.html.emit`, `flm.html.emit-pieces`), the resolve stage
/// `flm.html.resolve-definitions` and the regions stage `flm.html.regions` read
/// them; the final stage reads only the regions.
///
/// # Examples
///
/// ```
/// use flm_core::stdlib::backends::html::{DEFAULT_TITLE, HtmlRenderOptions};
///
/// let options = HtmlRenderOptions::default();
/// assert_eq!(options.title, DEFAULT_TITLE);
/// assert_eq!(options.lang, None);
/// assert!(!options.source_spans);
/// assert_eq!(options.run_in_stop, ".");
/// assert!(options.definitions.is_empty());
/// assert!(options.required_definitions.is_empty());
/// assert!(options.heading_tags.is_empty());
/// assert_eq!(options.root_heading_level, 1);
/// ```
/// The title a page carries when neither the document nor the render request
/// gives one: `FLM document` ([`HtmlRenderOptions::title`]).
pub const DEFAULT_TITLE: &str = "FLM document";
// --- the feature --------------------------------------------------------------------------
/// The `html` feature, which registers the HTML backend: its construct
/// element, its definitions, its tables, its render options, its stages, the
/// `html` output and the `html` workflow (the [module documentation](self)
/// lists them).
///
/// Use [`feature()`] to obtain it as a shared value that a package entry can
/// list; [`feature()`] also says which features must be registered beside it.
;
/// Returns the `html` feature ([`HtmlBackend`]) as a shared value, ready to be
/// listed in a package entry.
///
/// A package that lists it must also list three other features:
///
/// - the `lowering` feature, which registers the presentation vocabulary this
/// backend writes natively;
/// - the `pieces` feature
/// ([`pieces::feature`](crate::stdlib::backends::pieces::feature())), which
/// declares the render option the pieces stage reads; without it, every plan
/// of a registry holding this backend fails;
/// - the `check` feature ([`check_feature`](crate::stdlib::check_feature)),
/// which declares the capability [`flm.validated`](crate::stdlib::VALIDATED)
/// that the `html` workflow demands beside its output.
///
/// # Examples
///
/// ```
/// use flm_core::stdlib::backends::html;
///
/// assert_eq!(html::feature().info().name.as_str(), html::FEATURE_NAME);
/// ```