flm_core/stdlib/backends/html/feature.rs
1//! The `html` feature: registers the HTML backend, its render options, the
2//! `html` output and the `html` workflow, and declares the four names the rest
3//! of the library uses to refer to them.
4//!
5//! The `html` feature ([`FlmFeature`]),
6//! implemented by [`HtmlBackend`] and obtained with [`feature()`], registers:
7//!
8//! - the construct element [`flm.pres.html.tag`](super::construct::TAG), one
9//! HTML tag as a node of the lowered tree;
10//! - the seven stylesheets and the formula renderer's script that the backend
11//! ships, the definitions table `flm.html.definitions` and the stage that
12//! writes it ([`super::defs`]);
13//! - the tables the backend's stages write: the lowered trees
14//! (`flm.lowered.html`), the HTML of each tree (`flm.output.html`), the page's
15//! artifact set (`flm.output.html.document`) with its capability
16//! [`flm.output.html.singlefile`](super::stages::SINGLEFILE), the artifact
17//! table `flm.output.html.artifacts` that the final stage reads, the lowered
18//! pieces (the document-level values a backend places beside the content,
19//! such as the title; [`Piece`](crate::core::piece::Piece))
20//! (`flm.lowered.html.pieces`), the HTML of each piece
21//! (`flm.output.html.pieces`) and the regions (`flm.output.html.regions`);
22//! - the stage that builds the lowered pieces ([`PiecesStage`] for the `html`
23//! backend), the stage `flm.html.emit-pieces` and the regions stage
24//! `flm.html.regions`;
25//! - the backend's regions output
26//! ([`RegionsOutput`]), contributed to
27//! the service slot `flm.output.regions`, so that a host's own page assembler
28//! can find the regions;
29//! - the backend itself, with its native element set and its three stages
30//! ([`super::stages::stages`]);
31//! - the `html` output and the `html` workflow.
32//!
33//! The render options are [`HtmlRenderOptions`], declared with the feature's
34//! settings under the feature name `html`, and
35//! [`HtmlAllowedUrlSchemes`], the URL schemes the page may reference, which the
36//! feature declares beside its settings so that only Rust code sets it ([who
37//! decides which schemes are
38//! allowed](super::address#who-decides-which-schemes-are-allowed)). The backend's name is the base of
39//! the names of its stages (`flm.html.*`) and of its lowered-trees table
40//! (`flm.lowered.html`). The identifiers of the conditions it reports
41//! (`flm.html.*`) take the feature's name, [`FEATURE_NAME`], which is also
42//! `html`.
43//!
44//! A future HTML output, such as a multi-file one, is meant to add a second
45//! final stage to this backend rather than a backend of its own. A feature of
46//! another crate whose lowering rule stages an HTML tag node (builds it into
47//! the lowered tree; see [`Lowerer`](crate::core::lowering::Lowerer)) declares
48//! the construct element through a peer declaration
49//! ([`PeerName`](crate::core::registry::PeerName),
50//! [`FeatureBuilder::peer_element`](crate::core::registry::FeatureBuilder::peer_element))
51//! instead of depending on this feature.
52//!
53//! # The elements the backend writes natively
54//!
55//! The native set ([`native_elements`]) holds 29 elements: every element of the
56//! [presentation vocabulary](crate::stdlib::backends::pres), the construct
57//! element [`flm.pres.html.tag`](super::construct::TAG), and the six
58//! [structural elements](crate::guide::concepts_overview#structural-elements)
59//! of [`FLOW_THROUGH`] that the backend emits natively, without a lowering rule,
60//! because they carry nothing an HTML page has to translate: `flm.text`,
61//! `flm.group`, `flm.opaque-wrapper`, `flm.comment`, `flm.container` and
62//! `flm.parbreak`.
63//!
64//! The native set holds **no element another feature owns**, and in
65//! particular not the reference element `flm.ref`. The `refs` feature's own
66//! lowering rule for `flm.ref` is therefore selected, and because that rule
67//! reads the resolved references, the plan schedules the stage that resolves
68//! them and, before it, the stage that computes the anchors. A heading then
69//! reaches the emitter with the anchor that becomes its `id`. In a registry
70//! without the `refs` feature, a heading carries no anchor and therefore no
71//! `id`, as on every other backend.
72//!
73//! This backend needs the same [tree
74//! state](crate::guide::concepts_overview#frozen-trees-and-computed-data) as the
75//! text backend (blocks
76//! structured, user definitions expanded), so one plan serves both, and a
77//! request for the `text` and the `html` outputs together is one run. A
78//! request for `html` and `latex-recomposed` together is refused, as one for
79//! `text` and `latex-recomposed` is, because those backends need different
80//! tree states.
81//!
82//! # What the `html` workflow demands
83//!
84//! The `html` [workflow](crate::core::registry::WorkflowDef) lists the `html`
85//! output and also demands (asks the plan for a stage that provides;
86//! [`PlanRequest::demand`](crate::core::plan::PlanRequest::demand)) the
87//! [capability](crate::core::registry::CapabilityDef)
88//! [`flm.validated`](crate::stdlib::VALIDATED), which the document's checks
89//! provide together, so that every workflow runs the same checks over a
90//! document. The `check` feature
91//! ([`check_feature`](crate::stdlib::check_feature)) declares that
92//! capability, so a registry that holds this backend must hold the `check`
93//! feature too.
94//!
95//! See the [module documentation](super) for the backend as a whole.
96
97use std::collections::{BTreeMap, BTreeSet};
98use std::sync::Arc;
99
100use crate::core::settings::SettingsDecl;
101use crate::core::artifact::ArtifactSet;
102use crate::core::registry::{
103 BackendDef, BuildError, CapabilityDef, DefContent, FeatureBuilder, FeatureInfo, FlmFeature,
104 OutputDef, WorkflowDef,
105};
106use crate::lang::structural;
107use crate::model::names::{ElementName, Name};
108use crate::model::options::Bind;
109use crate::stdlib::VALIDATED;
110use crate::stdlib::backends::lowering::{LoweredTrees, lowered_table_name};
111use crate::stdlib::backends::pieces::{LoweredPieces, PiecesStage, lowered_pieces_table_name};
112use crate::stdlib::backends::pres;
113
114use crate::core::region::RegionsOutput;
115use crate::stdlib::backends::lowering::REGIONS_SLOT;
116
117use super::address::HtmlAllowedUrlSchemes;
118use super::construct;
119use super::defs;
120use super::stages::{
121 HtmlEmitPiecesStage, HtmlRegionsStage, PIECES_TABLE, REGIONS,
122 ARTIFACTS, DOCUMENT, EXTENSION, MEDIA_TYPE, OUTPUT_TABLE, SINGLEFILE, stages,
123};
124
125/// The feature's registered name, `html`. It is also the middle part of the
126/// identifiers of the conditions this backend reports, `flm.html.*`, and the
127/// name under which the feature's settings are declared.
128pub const FEATURE_NAME: &str = "html";
129
130/// The declaration of the feature's settings: the fields of
131/// [`HtmlRenderOptions`] are its settings keys, bound to the render request,
132/// and the key `run_in_stop` is marked as text in FLM markup
133/// ([`Mark::Markup`](crate::core::settings::Mark::Markup)). See
134/// [`crate::core::settings`].
135fn settings() -> SettingsDecl {
136 SettingsDecl::new(FEATURE_NAME)
137 .options::<HtmlRenderOptions>(
138 Bind::Render,
139 "the page's title and language tag; whether the elements written for a node carry \
140 their position in the source; the stop written after a run-in heading's title; \
141 what the host delivers in place of the declared content of a stylesheet or script; \
142 the stylesheets and scripts the host requires for the page in addition to those its \
143 content requires; the tag each heading kind is written with; and the heading level \
144 written as `<h1>`. Set per render request.",
145 )
146 .markup("run_in_stop")
147}
148
149/// The backend's name, `html`.
150///
151/// A lowering rule marked as the default on this backend refers to it by this
152/// name, and the names of the backend's lowering stage (`flm.html.lower`) and
153/// lowered-trees table (`flm.lowered.html`) are derived from it.
154pub const BACKEND: &str = "html";
155
156/// The `html` output's name.
157///
158/// It is spelled like the backend's name but is the name of an output: a
159/// workflow lists it
160/// ([`WorkflowDef::output`](crate::core::registry::WorkflowDef::output)), and a
161/// host looks the output up by it
162/// ([`FlmRegistry::output`](crate::core::registry::FlmRegistry::output)).
163pub const OUTPUT: &str = "html";
164
165/// The `html` workflow's name.
166///
167/// It is spelled like the backend's name but is the name of a workflow, the
168/// argument [`Plan::for_workflow`](crate::core::plan::Plan::for_workflow)
169/// takes.
170pub const WORKFLOW: &str = "html";
171
172/// The six [structural elements](crate::guide::concepts_overview#structural-elements)
173/// the HTML backend emits natively, without a lowering rule, beside the
174/// presentation vocabulary and the construct element: text, groups, opaque
175/// wrappers, source comments, containers and paragraph breaks (see the [module
176/// documentation](self)).
177pub const FLOW_THROUGH: [&str; 6] = [
178 structural::TEXT,
179 structural::GROUP,
180 structural::OPAQUE_WRAPPER,
181 structural::COMMENT,
182 structural::CONTAINER,
183 structural::PARBREAK,
184];
185
186/// Returns the backend's native element set, the elements its emitter writes
187/// without a lowering rule: every element of the presentation vocabulary
188/// ([`pres::ALL`]), the construct element
189/// [`flm.pres.html.tag`](super::construct::TAG), then the elements of
190/// [`FLOW_THROUGH`], in that order (29 elements).
191///
192/// The set holds no element another feature owns; the [module
193/// documentation](self#the-elements-the-backend-writes-natively) says why.
194///
195/// # Examples
196///
197/// ```
198/// use flm_core::stdlib::backends::html::{FLOW_THROUGH, TAG, native_elements};
199/// use flm_core::stdlib::backends::pres;
200///
201/// let native = native_elements();
202/// assert_eq!(native.len(), pres::ALL.len() + 1 + FLOW_THROUGH.len());
203/// assert_eq!(native.len(), 29);
204/// assert!(native.iter().any(|element| element.as_str() == TAG));
205/// // No element another feature owns: a reference is lowered by the `refs`
206/// // feature's own rule, so the plan schedules the stage computing the anchors.
207/// assert!(!native.iter().any(|element| element.as_str() == "flm.ref"));
208/// ```
209pub fn native_elements() -> Vec<ElementName> {
210 pres::ALL
211 .iter()
212 .chain(std::iter::once(&construct::TAG))
213 .chain(FLOW_THROUGH.iter())
214 .map(|name| ElementName::from(*name))
215 .collect()
216}
217
218// --- the render options -------------------------------------------------------------------
219
220/// The delivery of a style or script definition: how the definition reaches
221/// the page.
222///
223/// A style or script definition ([`StyleDef`](crate::core::registry::StyleDef),
224/// [`ScriptDef`](crate::core::registry::ScriptDef)) is a stylesheet or a script
225/// that a feature's output depends on, recorded in the registry under an
226/// identifier; the backend that writes the output decides its *delivery*:
227/// written into the output, loaded from an address, or left to the host (see
228/// [style and script
229/// definitions](crate::guide::concepts_overview#style-and-script-definitions)).
230///
231/// This type has two uses:
232///
233/// - a host gives one per definition identifier in the render option
234/// [`HtmlRenderOptions::definitions`], in place of the definition's declared
235/// content;
236/// - each row of the definitions table records the delivery the definition
237/// ended up with
238/// ([`ResolvedDefinition::delivery`](super::defs::ResolvedDefinition::delivery)).
239///
240/// An entry of the option replaces the declared content and never changes
241/// *what* the document requires: the definition is still listed in the
242/// definitions table, so a host or a bundler reading that table learns that the
243/// document needs it.
244///
245/// A delivery is an ordered list of parts, as a definition's declared content
246/// is, and an entry of the option replaces the whole list. The formula
247/// renderer's definition, for example, holds a configuration and then the
248/// address of the program: a host that wants its own address writes both
249/// parts, because a page without the configuration renders mathematics
250/// wrongly.
251#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Deserialize)]
252#[derive(schemars::JsonSchema)]
253#[serde(rename_all = "kebab-case")]
254pub enum DefinitionOverride {
255 /// The host's own page or bundle supplies the definition, and the page
256 /// writes nothing for it.
257 ///
258 /// An empty list of parts also writes nothing, but only this variant tells
259 /// a reader of the definitions table that the host supplies the
260 /// definition.
261 ProvidedByHost,
262 /// The page writes these parts, in this order. Each part is text written
263 /// into the page, an address the page loads, or a file, which this library
264 /// does not read and reports
265 /// ([`DefinitionNotInlinable`](super::defs::DefinitionNotInlinable)).
266 Parts(Vec<DefContent>),
267}
268
269/// The render options of the HTML backend: the page's title and language, the
270/// source-position attribute, the stop after a run-in heading, how stylesheets
271/// and scripts are delivered, the stylesheets and scripts the host adds to the
272/// page, how headings are tagged, and the heading level written as `<h1>`.
273///
274/// The option type is declared with [`Bind::Render`], so its values come from
275/// the render request rather than from the document (see [settings, options and
276/// configuration](crate::guide::concepts_overview#settings-options-and-configuration)).
277/// The values are set on the plan request
278/// ([`PlanRequest::render_options`](crate::core::plan::PlanRequest::render_options())),
279/// so two runs asking for different titles use two plans. The emit stages
280/// (`flm.html.emit`, `flm.html.emit-pieces`), the resolve stage
281/// `flm.html.resolve-definitions` and the regions stage `flm.html.regions` read
282/// them; the final stage reads only the regions.
283///
284/// # Examples
285///
286/// ```
287/// use flm_core::stdlib::backends::html::{DEFAULT_TITLE, HtmlRenderOptions};
288///
289/// let options = HtmlRenderOptions::default();
290/// assert_eq!(options.title, DEFAULT_TITLE);
291/// assert_eq!(options.lang, None);
292/// assert!(!options.source_spans);
293/// assert_eq!(options.run_in_stop, ".");
294/// assert!(options.definitions.is_empty());
295/// assert!(options.required_definitions.is_empty());
296/// assert!(options.heading_tags.is_empty());
297/// assert_eq!(options.root_heading_level, 1);
298/// ```
299#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Deserialize)]
300#[derive(schemars::JsonSchema)]
301#[serde(default, deny_unknown_fields)]
302pub struct HtmlRenderOptions {
303 /// The page's title when the document states none: the words written into
304 /// `<title>` (the output region [`title`](crate::core::region::TITLE)) when
305 /// the render places no title piece
306 /// ([`flm.metadata.title`](crate::stdlib::features::metadata::TITLE)) or the title
307 /// piece holds no words. The default is [`DEFAULT_TITLE`].
308 pub title: String,
309 /// The page's language as a language tag (`en`, `de-CH`), written as the
310 /// `lang` attribute of `<html>` (the output region
311 /// [`lang`](crate::core::region::LANG)). `None`, the default, writes no
312 /// attribute, because a page that claims a language it is not written in is
313 /// worse for a reader using a screen reader than one that claims none.
314 pub lang: Option<String>,
315 /// Whether the emitter writes the attribute `data-flm-source-span`, which
316 /// records where in the source a node was written, on the element it
317 /// writes for each node.
318 ///
319 /// The attribute is written on every element written for a node, inline
320 /// or block-level, once per node, when the node's position can be traced
321 /// back to a source with a name. Its value is a JSON array of the source's
322 /// name, the first byte of the range and the byte just past its end
323 /// (`["book/ch1.flm",0,8]`), so a script reads it back with `JSON.parse`.
324 /// It is written between single quotation marks, which HTML allows, so the
325 /// raw page shows the JSON as JSON. Off by default: the attribute serves
326 /// tools that map a place in the page back to the document, and it adds
327 /// bytes to every page.
328 pub source_spans: bool,
329 /// The stop written after the title of a run-in heading, so that
330 /// `\paragraph{Note} Some content.` reads as `Note. Some content.` A
331 /// run-in heading is a heading set at the start of the paragraph it
332 /// introduces, on the paragraph's first line
333 /// ([`headings`](crate::stdlib::features::headings)). The default is
334 /// [`DEFAULT_RUN_IN_STOP`](crate::stdlib::backends::pres::DEFAULT_RUN_IN_STOP),
335 /// a period; the empty text writes none.
336 ///
337 /// The stop is written as escaped text inside the run-in decoration's
338 /// `<span>`, after the title, so a reader copies it with the rest of the
339 /// page and a host that replaces the stylesheet keeps it. It is written
340 /// only when the title holds text and does not already end in sentence
341 /// punctuation
342 /// ([`ends_in_sentence_punctuation`](crate::stdlib::backends::pres::ends_in_sentence_punctuation)).
343 /// That test looks only at the characters the title ends with, so a title
344 /// that ends in a formula, or in a box an author's own command draws, gets
345 /// the stop after it. A host that needs headings written another way
346 /// registers a lowering rule or a stage of its own ([the extension
347 /// guide](crate::guide::extending#lowering-rules)).
348 pub run_in_stop: String,
349 /// The deliveries the host gives in place of the declared content of
350 /// style and script definitions, by definition identifier
351 /// ([`DefinitionOverride`]). Empty by default: every definition is then
352 /// delivered as its declaration says.
353 ///
354 /// An identifier that no feature declares is ignored and reported as the
355 /// Warning [`flm.html.unknown-definition`](super::defs::UnknownDefinition).
356 pub definitions: BTreeMap<Name, DefinitionOverride>,
357 /// The style and script definitions the host requires for the page as a
358 /// whole, by identifier, in addition to those the document's content
359 /// requires. Empty by default: a page then carries exactly what its content
360 /// needs.
361 ///
362 /// A host that adds something of its own to every page it serves (for
363 /// example a script that keeps an open page in step with the document, and
364 /// its stylesheet) registers it as a definition of one of its features and
365 /// lists its identifier here, rather than editing the page after it was
366 /// written. A definition listed here appears once in the [definitions
367 /// table](super::defs::DEFINITIONS_TABLE), like any other, whether or not
368 /// the content requires it too, and reaches the page the same way;
369 /// [`definitions`](Self::definitions) still decides its delivery. An
370 /// identifier that no feature declares is reported as the Error
371 /// [`flm.html.unknown-requirement`](super::defs::UnknownRequirement), as a
372 /// requirement of the content would be.
373 pub required_definitions: BTreeSet<Name>,
374 /// The tag a block heading of each heading kind is written with, keyed by
375 /// the heading kind's name (`section`), the tag written without angle
376 /// brackets (`h2`). Empty by default. A heading kind the map does not
377 /// list is written `<h1>` to `<h6>` by its level
378 /// ([`root_heading_level`](Self::root_heading_level)).
379 ///
380 /// The title above every list of xnotes (notes set apart from the running
381 /// text, such as footnotes; see
382 /// [`xnotes`](crate::stdlib::features::xnotes)) is a heading of the
383 /// heading kind `xnotes`
384 /// ([`TITLE_HEADING`](crate::stdlib::features::xnotes::TITLE_HEADING)),
385 /// for every xnote kind: mapping `xnotes` to `h3` writes every such title
386 /// `<h3>`.
387 ///
388 /// The tag is not part of the [HTML contract](super::CONVENTIONS): the
389 /// attributes a block heading carries (`data-flm-heading`,
390 /// `data-flm-level`, `data-flm-toc`) are the same regardless of its tag. A
391 /// heading of a run-in kind is written as a `<span>` carrying the same
392 /// attributes inside its run-in decoration, never with this tag. A tag
393 /// that is not a writable HTML tag name
394 /// ([`is_valid_tag_name`](super::names::is_valid_tag_name)) is reported as
395 /// [`flm.html.invalid-name`](super::emit::InvalidName), and the heading is
396 /// written with the tag of its level.
397 pub heading_tags: BTreeMap<Name, String>,
398 /// The heading level the page writes as its first-level heading, `<h1>`.
399 ///
400 /// A heading's level is a number counted from zero, the smaller the outer
401 /// ([`HeadingPayload::level`](crate::stdlib::backends::pres::HeadingPayload::level));
402 /// a heading at this level is `<h1>`, one level deeper `<h2>`, and so on
403 /// to `<h6>`, which every deeper level shares. The default is
404 /// [`DEFAULT_ROOT_HEADING_LEVEL`](crate::stdlib::backends::pres::DEFAULT_ROOT_HEADING_LEVEL),
405 /// 1, the level of a section: a section is `<h1>`. A root of 0 writes a
406 /// kind declared at level 0, a chapter, `<h1>` and a section `<h2>`; a
407 /// root of 2 writes the content of one section with its subsections as
408 /// the first-level headings.
409 ///
410 /// A heading whose level is less than the root is reported as
411 /// [`flm.pres.heading-above-root`](crate::stdlib::backends::pres::HeadingAboveRoot)
412 /// and written `<h1>`, or with its tag where
413 /// [`heading_tags`](Self::heading_tags) maps its kind: the mapping decides
414 /// the tag and nothing else. The attribute `data-flm-level` holds a
415 /// heading's own level regardless of the root. The option concerns the
416 /// page's tags only: the numbering, the run-in headings and the
417 /// identifiers read a heading's own level, as every other output does. The
418 /// text output has the same option
419 /// ([`TextRenderOptions::root_heading_level`](crate::stdlib::backends::text::TextRenderOptions::root_heading_level)).
420 pub root_heading_level: u8,
421}
422
423/// The title a page carries when neither the document nor the render request
424/// gives one: `FLM document` ([`HtmlRenderOptions::title`]).
425pub const DEFAULT_TITLE: &str = "FLM document";
426
427impl Default for HtmlRenderOptions {
428 fn default() -> HtmlRenderOptions {
429 HtmlRenderOptions {
430 title: String::from(DEFAULT_TITLE),
431 lang: None,
432 source_spans: false,
433 run_in_stop: String::from(pres::DEFAULT_RUN_IN_STOP),
434 definitions: BTreeMap::new(),
435 required_definitions: BTreeSet::new(),
436 heading_tags: BTreeMap::new(),
437 root_heading_level: pres::DEFAULT_ROOT_HEADING_LEVEL,
438 }
439 }
440}
441
442// --- the feature --------------------------------------------------------------------------
443
444/// The `html` feature, which registers the HTML backend: its construct
445/// element, its definitions, its tables, its render options, its stages, the
446/// `html` output and the `html` workflow (the [module documentation](self)
447/// lists them).
448///
449/// Use [`feature()`] to obtain it as a shared value that a package entry can
450/// list; [`feature()`] also says which features must be registered beside it.
451#[derive(Debug, Default, Clone, Copy)]
452pub struct HtmlBackend;
453
454impl FlmFeature for HtmlBackend {
455 fn info(&self) -> FeatureInfo {
456 FeatureInfo::new(FEATURE_NAME, "HTML backend").docs(
457 "HTML output for a browser: the construct element `flm.pres.html.tag`, the `html` \
458 backend, the `html` output and the `html` workflow",
459 )
460 }
461
462 fn settings(&self) -> Option<SettingsDecl> {
463 Some(settings())
464 }
465
466 fn register(&self, b: &mut FeatureBuilder<'_>) -> Result<(), BuildError> {
467 construct::register(b)?;
468 defs::register(b)?;
469 // Not among the settings: only Rust code sets which schemes the page's
470 // links and images may have.
471 b.options_with_docs::<HtmlAllowedUrlSchemes>(
472 Bind::Render,
473 "the URL schemes the page's links and images may have; set per render request, by \
474 Rust code only",
475 )?;
476 b.table_named::<LoweredTrees>(
477 lowered_table_name(&BACKEND.into()),
478 "the HTML backend's lowered trees, one per document tree",
479 )?;
480 b.table(
481 OUTPUT_TABLE,
482 "the HTML of each document tree, and the stylesheets and scripts each tree requires",
483 )?;
484 b.table::<ArtifactSet>(DOCUMENT, "the page as the entry artifact, and the files beside it")?;
485 b.table::<ArtifactSet>(
486 ARTIFACTS,
487 "files a stage produces for the page to link to, added to the page's set",
488 )?;
489 b.capability(
490 CapabilityDef::new(SINGLEFILE)
491 .refines(DOCUMENT.name())
492 .default()
493 .docs(
494 "the page written as one HTML file",
495 ),
496 )?;
497 b.table_named::<LoweredPieces>(
498 lowered_pieces_table_name(&BACKEND.into()),
499 "the pieces that the render request places, lowered for the HTML backend",
500 )?;
501 b.stage(Arc::new(PiecesStage::new(BACKEND)))?;
502 b.table(
503 PIECES_TABLE,
504 "the HTML of each piece that the render request places, and the stylesheets and \
505 scripts each piece requires",
506 )?;
507 b.stage(Arc::new(HtmlEmitPiecesStage))?;
508 b.table(REGIONS, "the parts the page is made of: the content, the pieces, the stylesheets \
509 and the scripts")?;
510 b.stage(Arc::new(HtmlRegionsStage))?;
511 b.contribute_to::<RegionsOutput>(
512 REGIONS_SLOT,
513 Arc::new(RegionsOutput {
514 output: OUTPUT.into(),
515 backend: BACKEND.into(),
516 document: DOCUMENT.name().into(),
517 capability: SINGLEFILE.into(),
518 regions: REGIONS.handle(),
519 artifacts: vec![ARTIFACTS.handle()],
520 }),
521 )?;
522 let (lowering, emit, final_stage) = stages();
523 b.backend(
524 BackendDef::new(BACKEND, native_elements(), lowering, emit, final_stage)
525 .docs("HTML for a browser"),
526 )?;
527 b.output(
528 OutputDef::new(OUTPUT, SINGLEFILE, DOCUMENT.name(), MEDIA_TYPE, EXTENSION)
529 .docs("the document as one HTML page"),
530 )?;
531 b.workflow(
532 WorkflowDef::new(WORKFLOW)
533 .output(OUTPUT)
534 .demand(VALIDATED)
535 .docs("render the document as an HTML page, running every check"),
536 )?;
537 Ok(())
538 }
539}
540
541/// Returns the `html` feature ([`HtmlBackend`]) as a shared value, ready to be
542/// listed in a package entry.
543///
544/// A package that lists it must also list three other features:
545///
546/// - the `lowering` feature, which registers the presentation vocabulary this
547/// backend writes natively;
548/// - the `pieces` feature
549/// ([`pieces::feature`](crate::stdlib::backends::pieces::feature())), which
550/// declares the render option the pieces stage reads; without it, every plan
551/// of a registry holding this backend fails;
552/// - the `check` feature ([`check_feature`](crate::stdlib::check_feature)),
553/// which declares the capability [`flm.validated`](crate::stdlib::VALIDATED)
554/// that the `html` workflow demands beside its output.
555///
556/// # Examples
557///
558/// ```
559/// use flm_core::stdlib::backends::html;
560///
561/// assert_eq!(html::feature().info().name.as_str(), html::FEATURE_NAME);
562/// ```
563pub fn feature() -> Arc<dyn FlmFeature> {
564 Arc::new(HtmlBackend)
565}