Skip to main content

Module text

Module text 

Source
Expand description

The text backend: it prints a document as plain text, wrapped to a line width, through the layout engine.

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). The text backend is registered by the text feature (TextBackend, feature()), which also registers the text output and the text workflow (WORKFLOW). The standard features (stdlib::add_features) include that feature together with the features it needs (see feature()).

§Using the backend

A caller builds a plan for the text workflow (Plan::for_workflow with WORKFLOW), runs it over a document, and reads one of two tables:

  • TEXT_OUTPUT (flm.output.text), a TextOutput: the printed text, its position marks, which give for each printed part the presentation node it was printed from (TextMark), and its style marks, which give the printed ranges whose content carries a property plain text cannot show, such as bold weight or a link’s address (TextStyleMark);
  • TEXT_DOCUMENT (flm.output.text.document), the text output’s artifact set: one entry artifact text:document of media type text/plain.

The render options (TextRenderOptions) set the line width, the width of a tab, the stop after a run-in heading’s title, whether links print their address, the heading level printed as a first-level heading, how a table is drawn (TableFrame) and the characters of the rules under the headings (HeadingRules). A program that writes the text to a medium able to show what plain text cannot reads the style marks; the extension profile-tty, which is compiled into the flm program, paints the printed text from them for a terminal, under the same render options. The plain-text backend, in the rendering guide, shows a complete run.

§The stages

The text backend writes natively every element of the presentation vocabulary, its two construct elements (flm.pres.text.flush-right, content set at the right edge of its line, and flm.pres.text.ruled, blocks set between rule lines), and the six structural elements of FLOW_THROUGH (see native_elements). A plan of the text workflow runs, in order:

  1. the lowering stage flm.text.lower: the shared LoweringStage for this backend, which writes the lowered trees into flm.lowered.text;
  2. the pieces stage flm.text.pieces: the shared PiecesStage for this backend, which lowers the pieces the render places (document-level values such as a list of notes) into flm.lowered.text.pieces;
  3. the emit stage flm.text.emit (TextEmitStage), which prints the pieces placed before the content, the lowered trees in document order and the pieces placed after the content into one TextOutput;
  4. the regions stage flm.text.regions (TextRegionsStage), which writes that text as the output’s one output region, its content;
  5. the backend’s final stage flm.text.final (TextFinalStage), which writes the content as the artifact set of TEXT_DOCUMENT.

§Items of this module

Re-exports§

pub use construct::FLUSH_RIGHT;
pub use construct::FLUSH_RIGHT_GAP;
pub use construct::FlushRightPayload;
pub use construct::RULED;
pub use construct::RuledPayload;
pub use emit::Emitted;
pub use emit::FlushRightLines;
pub use emit::MissingSubtree;
pub use emit::NestingTooDeep;
pub use emit::NoWorkerThread;
pub use emit::PiecePlacement;
pub use emit::SubtreeCycle;
pub use emit::TEXT_OUTPUT;
pub use emit::TextMark;
pub use emit::TextOutput;
pub use emit::TextStyle;
pub use emit::TextStyleMark;
pub use emit::emit;
pub use feature::FEATURE_NAME;
pub use feature::FLOW_THROUGH;
pub use feature::TextBackend;
pub use feature::feature;
pub use feature::native_elements;
pub use stages::ARTIFACT_NAME;
pub use stages::ARTIFACT_OWNER;
pub use stages::BACKEND;
pub use stages::EMIT_STAGE;
pub use stages::EXTENSION;
pub use stages::FINAL_STAGE;
pub use stages::HeadingRules;
pub use stages::MEDIA_TYPE;
pub use stages::REGIONS_STAGE;
pub use stages::StageFailed;
pub use stages::TEXT_DOCUMENT;
pub use stages::TEXT_REGIONS;
pub use stages::TableFrame;
pub use stages::TextEmitStage;
pub use stages::TextFinalStage;
pub use stages::TextRegionsStage;
pub use stages::TextRenderOptions;
pub use stages::WORKFLOW;
pub use stages::stages;

Modules§

construct
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.
emit
The text emitter: it walks the text backend’s lowered trees and lowered pieces, builds one layout document from them, and prints it into a TextOutput.
feature
The text feature: it registers the text backend, its two construct elements, its native element set, its stages and tables, its render options, the text output and the text workflow.
stages
The text backend’s stages (emit, regions and final), its render options, the names of its stages and tables, and the condition its stages report.
superscript
The Unicode superscript and subscript forms of characters, the only table of these forms in the library: the text backend prints a superscript or a subscript span with them, and the numbering feature’s number formats #{unicodesuperscript} and #{unicodesubscript} write their digits with them.