Expand description
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.
The HTML contract is the set of class names and attributes a
stylesheet or a script may rely on in the HTML backend’s output. It is
written down once, here, as CONVENTIONS: the emitter reads a row before
it writes a node, markdown_table prints the rows for the rendering
guide, and tests compare the three
against each other, so that the output, this table and the documentation
cannot drift apart.
What the rows do not hold is a class name. A class is derived from the
name the element already has, by class_of_element and
class_of_role, and an attribute that is
not one of HTML’s own is
derived from the payload field’s name by data_attribute, as the custom
property of a length field is by style_property. Storing them
would let a class drift from the element it represents.
§A length on the page
A payload field holding a Length — a line’s indentation — is written
as a custom property (a CSS variable) in the element’s style
attribute, named after the field by style_property and valued with the
CSS length css_length spells, a tab being a multiple of the custom
property --flm-tab, which the core stylesheet declares on the page’s
root:
<div class="flm-pres-line" style="--flm-element-indent-left: calc(2 * var(--flm-tab))" data-flm-align="left">…</div>The property sets nothing by itself: the stylesheet applies it
(padding-left: var(--flm-element-indent-left, 0)), so a page’s own rules
decide what an indentation looks like and win over the shipped ones, and
a host changes the width of a tab with one property. A length is written
once, as the property, never also as a data-flm-… attribute, and a zero
length writes nothing, the stylesheet’s fallback being zero, so an
ordinary line carries no style attribute. Nothing else ever enters
style: the attribute holds the custom properties the HTML contract lists —
a payload’s length fields, and the ratio of two of them (below) — and
never a CSS property such as padding-left, which would outrank every
stylesheet rule (Written::Style, Written::Ratio).
One further kind of custom property is written by the same writer: the
ratio of two of a payload’s length fields, where a stylesheet needs
the proportions of a box and CSS cannot divide one length by another. An
image shown at a width and a height is written with its two lengths and
their ratio, which the core stylesheet reads so that the image keeps its
proportions where the page is narrower than it
(Written::Ratio, css_ratio):
<img class="flm-pres-image" src="plot.png" style="--flm-element-width: 5cm; --flm-element-height: 2in; --flm-element-aspect-ratio: 141.73228 / 144">Three things are outside the HTML contract, because a page must stay free to
change them: the whitespace between tags, the order the attributes are
written in, and the choice of tag. A stylesheet that selects
.flm-pres-span[data-flm-style="bold"] keeps working regardless of the tag the
emitter picks for it; one that selects strong does not, and is written
against something this backend never promised.
§How to read a row
Convention::tag says how the tag is chosen (TagRule).
Convention::fields lists every field of the element’s payload, in the
order the attributes derived from them are written, each with what becomes
of it (Written): an attribute HTML itself defines, a data-flm-…
attribute, a custom property in the style attribute, the node’s second
class, the class of a block before the node’s own, an attribute on each
entry of a list, or nothing.
Convention::style gives the style definition the emitter requires when
it writes the element. A requirement is only an identifier; how the
definition reaches the page is decided by the stage that resolves the
definitions (super::defs).
Structs§
- Block
Tag - One row of
BLOCK_TAGS: the tag a block of one role is written with. - Convention
- One row of the HTML contract: everything this backend writes for one presentation element.
- Field
- One field of a presentation payload, and what becomes of it.
Enums§
- TagRule
- How the tag of one presentation element is chosen.
- Written
- What the emitter does with one field of a presentation payload.
Constants§
- AUXILIARY_
CLASSES - The three classes of the HTML contract that are not derived from an element or a role, in the order this module declares them.
- CONTENT_
CLASS - The class the page’s content container carries, and the identifier it is
found by:
flm-content. - DEFAULT_
BLOCK_ TAG - The tag of a
flm.pres.blockwhose roleBLOCK_TAGSdoes not name, and of a block with no role:div. - LIST_
LABEL_ CLASS - The class of the element holding a list entry’s label where that label is
rich content rather than a marker a browser draws:
flm-pres-list-label. - PARAGRAPH_
FLOW_ TAG - The tag of a
flm.pres.parthat holds flow content (TagRule::ParagraphContent):div, which HTML allows to hold anything. - PARAGRAPH_
ROLE - The value of the
roleattribute of a paragraph written as aPARAGRAPH_FLOW_TAG:paragraph, the accessibility role of a paragraph, so that assistive technology reads the<div>as the paragraph it is. A paragraph written as a<p>carries norole, the tag saying as much. - SCRIPT_
MATHJAX - The script definition that turns the LaTeX of a formula into
mathematics in the reader’s browser:
flm.html.mathjax. - STYLE_
ATTRIBUTE - The attribute every length field of a payload is written in:
style, each field as one custom property (Written::Style). - STYLE_
CORE - The style definition of the elements every document has: paragraphs, blocks, spans, links, images and decorations.
- STYLE_
ERRORS - The style definition of what the output shows as an error: an unattributed callable, an element this backend cannot write, and the mark a rule leaves where it dropped something.
- STYLE_
HEADINGS - The style definition of the six heading sizes.
- STYLE_
LISTS - The style definition of lists, and of a run of lines with its alignment.
- STYLE_
MATH_ PASSTHROUGH - The style definition of passthrough mathematics (mathematics written into the page as source, for the MathJax script to typeset): displayed formulas, and content inside a formula.
- STYLE_
VERBATIM - The style definition of verbatim content, inline and as a block.
- TAB_
PROPERTY - The custom property holding the width of one tab, the unit of
indentation each backend sets through one setting of its own:
--flm-tab. The core stylesheet declares it on the page’s root,2emby default;css_lengthspells a length in tabs as a multiple of it. - UNKNOWN_
MARKER_ CLASS - The class of the two marker lines of an unattributed environment — the
\begin{…}and\end{…}lines the output shows as the author wrote them:flm-pres-unknown-marker.
Statics§
- BLOCK_
TAGS - The tag table of blocks: the tag a
flm.pres.blockis written with, keyed by the block’s role (TagRule::BlockRole). - CONVENTIONS
- The HTML contract, one row per element of the presentation vocabulary, in the vocabulary’s own order.
Functions§
- block_
tag - Returns the tag a
flm.pres.blockof the roleroleis written with: the tag of the row ofBLOCK_TAGSfor that role, elseDEFAULT_BLOCK_TAG. - css_
length - Returns
lengthspelled as a CSS length: a length in tabs ascalc(<amount> * var(--flm-tab))(TAB_PROPERTY), a length of any other unit as written, amount then unit (1.5em,10pt,3mm,0.25in,2cm). - css_
ratio - Returns the ratio
first ÷ secondof two lengths spelled as CSS’saspect-ratioreads a ratio,<first> / <second>with both written in points;Noneunless both are greater than zero and in physical units (pt,mm,cm,in), since a tab or an em has no fixed size to compare. - doc_
role_ value - Returns the value of the
roleattribute written for the document rolerole:doc-followed by the role’s stable name (DocRole::as_str) —doc-endnotes,doc-footnote,doc-noteref,doc-backlink,doc-bibliography,doc-bibliorefanddoc-toc, the roles the digital-publishing accessibility vocabulary defines for notes, cited works and a table of contents. - markdown_
table - Returns the HTML contract as a Markdown table: one line per element, with the element’s name, the tag, the classes, the attributes, what is dropped and the style definition.
- row
- Returns the row of the presentation element
element, orNonewhen the name is not one of the vocabulary’s. The emitter looks each node’s row up with it.