pub fn format(
value: &CounterValue,
style: &CounterStyle,
parent: Option<Parent<'_>>,
options: &FormatOptions,
) -> Result<Vec<Segment>, FormatError>Expand description
Writes one counter value in style and returns the segments of the
result: under the default writer, the word, the delimiters and the number,
as one segment that links to the value.
parent gives the within-joiner and the counters the value is numbered
within, and is None for a counter numbered within nothing. A
counter that the within-joiner refers to is written with its own ancestors
before it, so a within-joiner refers only to the counter immediately above
(Parent). options says which variant of the prefix words to use and
whether the word and the delimiters are written.
Under the default writer, the result is one segment with the link mark
0: one link covers the whole text, the word included. A counter style
written by another number writer may return other
segments. The call runs on a worker thread (on_worker_thread).
§Errors
FormatError::UndeclaredSubLevel when the value carries a sub-number at
a level for which style declares no format, FormatError::UnknownAncestor
when a within-joiner refers to a counter that is not among the ancestors,
and FormatError::NestingTooDeep or FormatError::Failed when the
content could not be built.
§Examples
use flm_core::lang::{build_language, LangInputs};
use flm_core::stdlib::features::numbering::{
format, CounterStyleDecl, CounterValue, Delimiters, FormatOptions, PrefixWords,
};
let lang = build_language(LangInputs::new());
let mut decl = CounterStyleDecl::new("example.style.equation");
decl.delimiters = Delimiters::new("(", ")");
decl.prefix_words = PrefixWords::new("Eq.~", "Eqs.~");
let style = decl.compile(&lang).expect("the style compiles");
let segments = format(&CounterValue::new(3), &style, None, &FormatOptions::new())
.expect("the number is written");
assert_eq!(segments.len(), 1);
assert_eq!(segments[0].link(), Some(0));