Private betav0.1.0
Docs
Format developer documentation

NumberingRule

A selector bound to a counter operation, applied to every match in document order.

A NumberingRule binds a selector to a counter operation and applies it to every match in document order. One rule numbers a chapter scheme or a figure counter. A CounterDef with resetEach provides restarts and a scope provides nesting, so a rule itself only advances and inserts.

Fields

NameTypeDescription
selectorRequired
stringCSS selector for the elements this rule numbers.
counter
stringThe counter this rule advances. Defaults to the selector.
increment
integerHow much to advance the counter on each match. Defaults to 1. Set it to 0 to insert a counter's value without advancing it.
set
integerWhen set, set the counter to this value instead of advancing it.
format
stringThe text inserted into each match, with {counter} placeholders.
counterStyle
stringThe counter style for the format placeholders. Defaults to the document's numbering style, or decimal.
insert
InsertWhere the formatted number goes relative to the match. Defaults to before.

Example

A two-level chapter scheme: each h1 advances the chapter, a <CounterDef> restarts the figure count under it, and each <figure> reads the chapter alongside its own number.

<Numbering>
  <CounterDef name="figure" resetEach="chapter" />
  <NumberingRule match="h1" counter="chapter" format="{chapter}. " />
  <NumberingRule match="figure" counter="figure" format="Figure {chapter}.{figure}: " />
</Numbering>
<Numbering>
  <CounterDef name="figure" reset-each="chapter" />
  <NumberingRule match="h1" counter="chapter" format="{chapter}. " />
  <NumberingRule match="figure" counter="figure" format="Figure {chapter}.{figure}: " />
</Numbering>
<template data-type="numbering">
  <template data-type="counter-def" data-name="figure" data-reset-each="chapter"></template>
  <template data-type="numbering-rule" data-match="h1" data-counter="chapter" data-format="{chapter}. "></template>
  <template data-type="numbering-rule" data-match="figure" data-counter="figure" data-format="Figure {chapter}.{figure}: "></template>
</template>

Usage

A rule fires for every element its match selector hits, in document order. The format text is inserted into each match, with {counter} placeholders that read the named counters; a placeholder can carry a style after a colon, as in {chapter:upper-roman}. Set increment to 0 to insert a counter's value without advancing it. A <CounterDef> with resetEach provides restarts, and a data-scope marker provides nesting, so a rule itself only advances and inserts. Author rules as <NumberingRule> children of <Numbering>.

Was this page helpful?