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, soflm.pres.block-headingis writtenflm-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_PREFIXfollowed by the field’s name with_and.turned into hyphens, so the fieldsource_spanis writtendata-flm-source-span.style_property— the custom property a payload’s length field is written as, in the element’sstyleattribute:STYLE_PROPERTY_PREFIXfollowed by the field’s name turned by the same rule, so the fieldindent_leftis 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
styleattribute for a payload’s length field:--flm-element-.
Functions§
- class_
of_ element - Returns the class a node of the presentation element
elementcarries: 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_PREFIXfollowed byfieldwith every_and.turned into-. - is_
valid_ attribute_ name - Returns whether
namemay be written as an attribute name: an ASCII letter followed by any number of ASCII letters, digits,-,_,:and.. - is_
valid_ tag_ name - Returns whether
namemay be written as a tag name: an ASCII letter followed by any number of ASCII letters, digits and-. - is_
valid_ token - Returns whether
namemay be written as one token: one class among the classes of an element, or one token of thedata-flm-kindattribute. - style_
property - Returns the custom property a payload’s length field is written as, in the
element’s
styleattribute:STYLE_PROPERTY_PREFIXfollowed byfieldturned into a name by the rule ofdata_attribute, every_and.turned into-.