Skip to main content

Module blocks

Module blocks 

Source
Expand description

The blocks feature lays out every document tree in paragraphs and blocks and resolves its text, in a rewrite stage that a plan includes when its capability is demanded or required, and it checks the tree contract.

§What the feature provides to an author

An author separates paragraphs with a blank line, and a block-level construct (a list, a quotation, a float) is placed between paragraphs, never inside one; a displayed formula stands inside the paragraph it is written in. The typographic spellings of TeX are shown as the characters they stand for: -- as an en dash, `` and '' as curly quotes, ... as an ellipsis, each family switched on or off by the feature’s configuration (BlocksConfig). The language guide describes these rules for authors: paragraphs, blocks and typography.

The work is done by the block-structure pass (crate::lang::rewrites::blocks), a plain function over a tree: it lays out each content region (a run of sibling nodes laid out together) as blocks, as inline content or unchanged, from the block role of each element and the layout each element declares for its arguments and body, and it resolves the text once (merged text nodes, collapsed whitespace, the typographic substitutions). This feature makes that pass a part of the pipeline.

§What the feature provides to the pipeline

A capability (CapabilityDef) is a registered dotted name for a state of processing that a stage brings about; a stage declares the capabilities it provides and requires, and a caller demands the capabilities it wants (stages, capabilities and plans). The feature registers:

  • BLOCKS (flm.blocks), the parent capability: a decision about block structure has been made. Two capabilities refine it (refinement): each is one way of satisfying it, and a plan that demands both is refused.
  • STRUCTURE (flm.blocks.structure), the rewrite stage (RewriteStage: a stage that turns one tree into another before the trees are frozen) that runs the block-structure pass over each tree, with the region layout of the tree’s top level (FragmentLayout) and the feature’s configuration. It publishes the trees it produces in the trees table STRUCTURED (flm.blocks.structured; a TreesTable, the table in which a rewrite stage publishes the trees it produces), which is also the capability it provides, the refinement of flm.blocks marked as the default: a plan that demands flm.blocks alone gets structured trees. A lowering rule that reads paragraphs requires flm.blocks.structured (the rule for paragraphs, for example), which puts the stage into a rendering plan.
  • RAW (flm.blocks.raw), a marker stage that does nothing and provides the capability of the same name, the other refinement of flm.blocks: the trees stay as parsed, without paragraphs and with the text unresolved. The lowering rules of the latex-recomposed backend require it, because that backend writes the document back as LaTeX source.
  • CONTRACT_CHECK (flm.blocks.check-contract, in the module check), the check stage that runs the tree-contract checker over every frozen tree and provides CONTRACT_CHECKED (flm.blocks.contract-checked), a member of the collection flm.validated that every standard workflow demands.
  • The settings declaration of BlocksConfig, whose fields are the feature’s settings keys (crate::core::settings).

§Configuration

BlocksConfig says which families of typographic substitution apply. It is the feature’s configuration, the plain Rust value the feature is constructed from (Blocks::new); it is fixed when the registry is built and cannot vary per document or per render (settings, options and configuration). The feature also gives the four flags of BlocksConfig as an input of the registry digest (FeatureBuilder::digest_input), a number computed from everything about a registry that can change what processing produces: the trees a run freezes depend on these flags, so two registries that differ in them must not share cached trees.

§Interaction with user definitions

A use site of a user definition (a place where a document uses a macro, environment or special character sequence that is defined by substitution; see crate::lang::rewrites::userdefs) that is not yet expanded can hide a paragraph break that the definition’s template holds, so the structure stage must not run before the plan has decided what happens to user definitions. Whenever the registry declares the capability USERDEFS (flm.userdefs, from the userdefs feature), the structure stage therefore requires it and is ordered after it. Either alternative of that capability satisfies the requirement: the use sites expanded in the tree (flm.userdefs.expanded), or kept in the tree for the lowering rules (flm.userdefs.kept). Under the same condition, the stage is also ordered after ALWAYS_EXPANDED (flm.userdefs.always-expanded), so that the rewrite stage flm.userdefs.expand-always runs before the structure stage whenever both are in the plan. An ordering never adds a stage to a plan: a stage runs because something requires a capability it provides, never because another stage is ordered after it. With no userdefs feature registered there are no user definitions, and the structure stage has no requirement.

§When the pass fails

When the block-structure pass fails over a tree, the stage returns a RewriteError carrying one Error diagnostic, and the tree is absent from every later table and from the frozen trees. Content nested more deeply than the recursion guard allows (flm.blocks.nesting-too-deep) gives RewriteError::NestingTooDeep; when the failure happens inside a synthesized value, value catch-up reports it again under a condition of its own (StageCx::resolve_value). Every other failure gives RewriteError::Failed.

§Items

Re-exports§

pub use self::check::CONTRACT_CHECK;
pub use self::check::CONTRACT_CHECKED;
pub use crate::lang::rewrites::blocks::BlocksConfig;

Modules§

check
The contract check stage of the blocks feature, flm.blocks.check-contract: it checks every frozen tree against the tree contract and reports each violation.

Structs§

Blocks
The blocks feature (FlmFeature): it registers the block-structure rewrite stage, the raw marker stage, the contract check stage, their capabilities and the feature’s settings. See the module documentation.

Constants§

BLOCKS
The parent capability flm.blocks: a decision about block structure has been made. Two capabilities refine it, STRUCTURED (the default) and RAW; a plan that demands both is refused. See the module documentation.
FEATURE
The feature’s registered name, blocks. It is also the middle segment of the names of the feature’s stages and diagnostics (flm.blocks.structure, flm.blocks.nesting-too-deep).
RAW
The name of the marker stage flm.blocks.raw and of the capability it provides: the refinement of BLOCKS under which the trees stay as parsed, without paragraphs and with the text unresolved. The marker stage does nothing; it exists so that a plan can choose this alternative, which excludes the STRUCTURE stage. The lowering rules of the latex-recomposed backend require it.
STRUCTURE
The name of the rewrite stage that runs the block-structure pass over each tree, flm.blocks.structure. The stage provides STRUCTURED.
STRUCTURED
The trees table flm.blocks.structured, in which the STRUCTURE stage publishes the trees it produces. A rewrite stage’s trees table has the name of the capability the stage provides, so flm.blocks.structured is also that capability: the refinement of BLOCKS marked as the default, so that a plan that demands flm.blocks alone gets structured trees.