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), aTextOutput: 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), thetextoutput’s artifact set: one entry artifacttext:documentof media typetext/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:
- the lowering stage
flm.text.lower: the sharedLoweringStagefor this backend, which writes the lowered trees intoflm.lowered.text; - the pieces stage
flm.text.pieces: the sharedPiecesStagefor this backend, which lowers the pieces the render places (document-level values such as a list of notes) intoflm.lowered.text.pieces; - 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 oneTextOutput; - the regions stage
flm.text.regions(TextRegionsStage), which writes that text as the output’s one output region, its content; - the backend’s final stage
flm.text.final(TextFinalStage), which writes the content as the artifact set ofTEXT_DOCUMENT.
§Items of this module
construct: the construct elementsFLUSH_RIGHT(flm.pres.text.flush-right) andRULED(flm.pres.text.ruled), their payloadsFlushRightPayloadandRuledPayload, the gapFLUSH_RIGHT_GAP, and their payload readers (construct::payload_readers), for a lowering rule that sets content at the right edge of a line or between rule lines.emit: the emitteremit(), the output tableTextOutputwith its position marks (TextMark) and its style marks (TextStyleMark,TextStyle), and the conditionsflm.text.flush-right-lines(FlushRightLines),flm.text.missing-subtree(MissingSubtree),flm.text.subtree-cycle(SubtreeCycle),flm.text.piece-placement(PiecePlacement),flm.text.nesting-too-deep(NestingTooDeep) andflm.text.worker-thread-unavailable(NoWorkerThread).stages: the names of the backend, its stages and tables,TextEmitStage,TextRegionsStage,TextFinalStage,TextRenderOptions, and the conditionflm.text.stage-failed(StageFailed).feature:TextBackend, the feature that registers the backend and its construct elements, and its native element set.superscript: the Unicode superscript and subscript forms with which a superscript or subscript span is printed.
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
textfeature: it registers the text backend, its two construct elements, its native element set, its stages and tables, its render options, thetextoutput and thetextworkflow. - 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.