Skip to main content

Module html

Module html 

Source
Expand description

The html backend: writes a document as an HTML page for a browser.

A backend is the registration bundle for one output format: the elements its emitter writes natively, a lowering stage, an emit stage and a final stage (BackendDef; see backends, lowering, and outputs). This module is the HTML backend. Its feature, HtmlBackend, registers the backend, the html output and the html workflow; the feature, the backend, the output and the workflow are all named html. A package that lists the feature (feature()) must also list the lowering, pieces and check features.

A run of the html workflow produces two things a caller can use:

  • the page: the entry artifact of the table flm.output.html.document (DOCUMENT), one HTML file that carries, or loads from an address, the stylesheets and the scripts the document requires;
  • the HTML of each document tree, without a page around it, in the table flm.output.html (HtmlFragments), with the identifiers of the style and script definitions each tree requires (the stylesheets and scripts its output depends on; see style and script definitions). A host that embeds the content in a page of its own reads this table, the table flm.output.html.pieces (HtmlPieces) of the pieces (document-level values a backend places beside the content, such as the title; Piece), and the definitions table flm.html.definitions (DEFINITIONS_TABLE).

The page is assembled from output regions (Regions): named parts of the page (the content, each piece, the stylesheets, the scripts, the title and the language) that the stage flm.html.regions writes once. The backend’s final stage assembles the page from them in a layout of its own; a host may assemble the same regions through a template of its own instead (see output regions and the final stage).

The HTML backend chapter of the rendering guide describes the output element by element.

§Writing HTML: escaping and the trust guarantee

Every byte of HTML this library writes goes through the modules below, and they guarantee one thing: text that comes from a document reaches the page escaped, and by no other way. Bytes are written unescaped only as a Markup value, or as the content of a <style> or a <script> through HtmlSink::raw_text_element; the documentation of each states what the caller must ensure.

The guarantee covers every byte outside mathematics. Inside a formula that the feature of the package math-passthrough writes, nothing is inspected and the author is trusted: what an author writes there reaches the reader’s formula renderer as typed. mathjax says what that means for a host and what such a host configures for itself.

  • escape — the escaping functions: one for text between tags, two for an attribute value.
  • markup — Markup, the value that carries HTML written without escaping.
  • sink — HtmlSink, the only interface through which HTML bytes are written: separate entry points for document text, for a tag and its attributes, for a markup value, and for the content of a <style> or a <script>; it also writes the line breaks and the indentation between block-level tags, and offers no way to read back what was written.
  • names — how the names of presentation elements, roles and payload fields become the class and attribute names of the HTML contract (the classes and attributes a stylesheet or a script may rely on in the output), and the checks a tag name, an attribute name, a role or a kind passes before it is written.
  • address — which addresses a link and an image may carry, the render option HtmlAllowedUrlSchemes that decides which URL schemes are allowed, and what happens to the other addresses.
  • construct — the construct element construct::TAG (flm.pres.html.tag): one HTML tag as a node of the lowered tree, for a lowering rule that must put HTML in the page that no shared presentation element carries.

§The backend’s stages, tables and conventions

  • conventions — the HTML contract as data: one row per presentation element, saying which tag, classes and attributes the output carries for it, which payload fields it cannot express, and which style definition gives it its default look.
  • emit — the emitter: emit_tree writes the HTML of one lowered tree; the conditions flm.html.invalid-name, flm.html.refused-address, flm.html.refused-in-math, flm.html.nesting-too-deep and flm.html.worker-thread-unavailable.
  • stages — the emit stages HtmlEmitStage and HtmlEmitPiecesStage, the regions stage HtmlRegionsStage, the final stage HtmlFinalStage, the tables they write and read, and the conditions flm.html.stage-failed, flm.html.missing-subtree, flm.html.subtree-cycle and flm.html.piece-placement.
  • defs — the stylesheets this backend ships, the stage ResolveDefinitionsStage that decides how each definition a document requires reaches the page, the table flm.html.definitions it writes, and the conditions flm.html.unknown-requirement, flm.html.unknown-definition and flm.html.definition-not-inlinable.
  • mathjax — the formula renderer’s script definition flm.html.mathjax, what its shipped configuration does, and the configuration a host writes for itself when it renders mathematics written by authors it does not trust.
  • page — how the regions are made from the tables (page::regions) and how the final stage assembles the page from them (page::assemble).
  • feature — HtmlBackend, the native element set (native_elements), the render options HtmlRenderOptions, and the four names FEATURE_NAME, BACKEND, OUTPUT and WORKFLOW.

Not yet implemented: a multi-file output, which would be a second final stage of this same backend.

Re-exports§

pub use address::AddressUse;
pub use address::DEFAULT_ALLOWED_URL_SCHEMES;
pub use address::HtmlAllowedUrlSchemes;
pub use address::InvalidUrlScheme;
pub use address::RefusedAddress;
pub use address::UrlScheme;
pub use address::check_address;
pub use construct::HtmlTagPayload;
pub use construct::TAG;
pub use construct::TagBody;
pub use defs::DEFINITIONS_TABLE;
pub use defs::DefinitionKind;
pub use defs::DefinitionNotInlinable;
pub use defs::DefinitionPartMissing;
pub use defs::NotInlinablePart;
pub use defs::RESOLVE_STAGE;
pub use defs::ResolveDefinitionsStage;
pub use defs::ResolvedDefinition;
pub use defs::ResolvedDefinitions;
pub use defs::STYLE_PAGE;
pub use defs::UnknownDefinition;
pub use defs::UnknownRequirement;
pub use conventions::AUXILIARY_CLASSES;
pub use conventions::CONTENT_CLASS;
pub use conventions::CONVENTIONS;
pub use conventions::Convention;
pub use conventions::LIST_LABEL_CLASS;
pub use conventions::TagRule;
pub use conventions::UNKNOWN_MARKER_CLASS;
pub use conventions::markdown_table;
pub use emit::AddressRefused;
pub use emit::DEPTH_LIMIT;
pub use emit::EmittedTree;
pub use emit::InvalidName;
pub use emit::NestingTooDeep;
pub use emit::NoWorkerThread;
pub use emit::RefusedInMath;
pub use emit::emit_tree;
pub use escape::escape_attr_into;
pub use escape::escape_attr_single_quoted_into;
pub use escape::escape_text_into;
pub use feature::BACKEND;
pub use feature::DEFAULT_TITLE;
pub use feature::DefinitionOverride;
pub use feature::FEATURE_NAME;
pub use feature::FLOW_THROUGH;
pub use feature::HtmlBackend;
pub use feature::HtmlRenderOptions;
pub use feature::OUTPUT;
pub use feature::WORKFLOW;
pub use feature::feature;
pub use feature::native_elements;
pub use markup::Markup;
pub use mathjax::MATHJAX_LOADER;
pub use mathjax::mathjax_script;
pub use names::class_of_element;
pub use names::class_of_role;
pub use names::data_attribute;
pub use names::is_valid_attribute_name;
pub use names::is_valid_tag_name;
pub use names::is_valid_token;
pub use names::style_property;
pub use page::HtmlRegions;
pub use sink::HtmlSink;
pub use sink::RawTextRefused;
pub use sink::TagBuilder;
pub use stages::ARTIFACT_NAME;
pub use stages::ARTIFACT_OWNER;
pub use stages::ARTIFACTS;
pub use stages::DOCUMENT;
pub use stages::EMIT_PIECES_STAGE;
pub use stages::EMIT_STAGE;
pub use stages::EXTENSION;
pub use stages::FINAL_STAGE;
pub use stages::HtmlEmitPiecesStage;
pub use stages::HtmlEmitStage;
pub use stages::HtmlFinalStage;
pub use stages::HtmlFragment;
pub use stages::HtmlFragments;
pub use stages::HtmlPiece;
pub use stages::HtmlPieces;
pub use stages::HtmlRegionsStage;
pub use stages::HtmlSegment;
pub use stages::MEDIA_TYPE;
pub use stages::MissingSubtree;
pub use stages::OUTPUT_TABLE;
pub use stages::PIECES_TABLE;
pub use stages::PiecePlacement;
pub use stages::REGIONS;
pub use stages::REGIONS_STAGE;
pub use stages::SINGLEFILE;
pub use stages::StageFailed;
pub use stages::SubtreeCycle;
pub use stages::stages;

Modules§

address
The address policy: which addresses the HTML backend writes into a page, and which it refuses.
construct
The HTML construct element: one HTML tag, as a node in the lowered tree.
conventions
The HTML contract as data: one row per presentation element saying which tag, classes and attributes this backend writes for it, which payload fields it cannot express, and which style definition gives it its default look.
defs
The stylesheets and the script this backend ships, and the stage that decides how each style or script definition a document requires reaches the page.
emit
The HTML emitter: writes the HTML of one lowered tree through the HTML sink.
escape
The escaping of document text for HTML: the three functions that rewrite the characters a browser would otherwise read as markup, one for text between tags and two for attribute values.
feature
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.
markup
The markup value: a string of HTML that the HTML sink writes without escaping it.
mathjax
The formula renderer’s script definition, flm.html.mathjax: what this backend ships so that a page can typeset the mathematics it carries, and what a host that does not trust the authors of that mathematics has to do for itself.
names
The naming functions of the HTML contract: how a presentation element’s name, a role and a payload field become the class names, attribute names and custom properties the output carries, and the checks a name passes before it is written.
page
The output regions of the HTML output, and the page the backend’s final stage assembles from them.
sink
The HTML sink: the only interface through which this library writes HTML bytes.
stages
The stages of the HTML backend after lowering, the tables they write and read, the artifact they produce, and the conditions they report.