Skip to main content

Module names

Module names 

Source
Expand description

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.

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, stated as data in CONVENTIONS. Its names are not written down one by one: the four functions below derive them from the names the presentation vocabulary already has, so that a class cannot drift from the element it represents.

  • class_of_element — the class every node of a presentation element carries: the element’s name with every hyphen doubled and every dot turned into one hyphen, so flm.pres.block-heading is written flm-pres-block--heading.
  • class_of_role — the second class, for the payload’s role: the dotted, feature-owned name saying what a container is (flm.heading.number; see decorations, roles and kinds), rewritten the same way (flm-heading-number).
  • data_attribute — the attribute one other payload field is written under: DATA_PREFIX followed by the field’s name with _ and . turned into hyphens, so the field source_span is written data-flm-source-span.
  • style_property — the custom property a payload’s length field is written as, in the element’s style attribute: STYLE_PROPERTY_PREFIX followed by the field’s name turned by the same rule, so the field indent_left is written --flm-element-indent-left.

The conventions table, not these functions, decides which field becomes which attribute and which elements carry a role: these functions only say how a name is written once the table has chosen it.

is_valid_token is the check a role and a kind token pass before they are written: the class attribute and data-flm-kind both hold a list of tokens separated by whitespace, so a name holding whitespace would be read as several of them.

The two remaining functions, is_valid_tag_name and is_valid_attribute_name, are the check applied to a tag or attribute name that comes from a construct node (a node that a lowering rule stages, that is, builds into the lowered tree, to write one HTML tag of its own; see Lowerer) or from the render options. Such a name is chosen by the rule’s author or the host, so it is checked before it is written; the names this module derives pass the check by construction.

Constants§

DATA_PREFIX
The prefix of every attribute this backend writes for a payload field that is not one of HTML’s own attributes: data-flm-.
STYLE_PROPERTY_PREFIX
The prefix of every custom property this backend writes in an element’s style attribute for a payload’s length field: --flm-element-.

Functions§

class_of_element
Returns the class a node of the presentation element element carries: the element’s name with every hyphen doubled and every dot turned into one hyphen.
class_of_role
Returns the class a node carries for its payload’s role: the role’s name with every hyphen doubled and every dot turned into one hyphen.
data_attribute
Returns the attribute name a payload field is written under: DATA_PREFIX followed by field with every _ and . turned into -.
is_valid_attribute_name
Returns whether name may be written as an attribute name: an ASCII letter followed by any number of ASCII letters, digits, -, _, : and ..
is_valid_tag_name
Returns whether name may be written as a tag name: an ASCII letter followed by any number of ASCII letters, digits and -.
is_valid_token
Returns whether name may be written as one token: one class among the classes of an element, or one token of the data-flm-kind attribute.
style_property
Returns the custom property a payload’s length field is written as, in the element’s style attribute: STYLE_PROPERTY_PREFIX followed by field turned into a name by the rule of data_attribute, every _ and . turned into -.