use std::sync::Arc;
use crate::core::registry::{BuildError, FeatureBuilder};
use super::aspects::{
ContentInOpaque, Decoration, IsContentInOpaque, IsDecoration, IsOpaque, OpaqueContent,
};
use super::names;
use super::payload::{
BlockPayload, CellsPayload, DecoMarkPayload, DecorationPayload, DroppedPayload,
HeadingPayload, ImagePayload,
LinePayload, LinesPayload, LinkPayload, ListPayload, MathPassthroughPayload, MathTextPayload,
ParPayload,
SpanPayload, SubtreePayload, UnknownPayload, UnsupportedPayload, VerbatimPayload,
};
pub fn register(b: &mut FeatureBuilder<'_>) -> Result<(), BuildError> {
b.presentation_element::<ParPayload>(names::PAR, "a laid-out paragraph (an inline run)")?;
b.presentation_element::<BlockPayload>(
names::BLOCK,
"a block container with a role and kinds (a run of blocks)",
)?;
b.presentation_element::<HeadingPayload>(
names::BLOCK_HEADING,
"a heading placed on its own between blocks, with its heading kind's name, a level and \
whether it is listed in a table of contents: a `body` content slot holding the title \
(inline content) and an optional `alt` content slot holding the alternative title",
)?;
b.presentation_element::<HeadingPayload>(
names::RUNIN_HEADING,
"the title of a run-in heading, inside its run-in decoration, with the same payload and \
content slots as a block heading: a `body` slot holding the title (inline content) and \
an optional `alt` slot holding the alternative title",
)?;
b.presentation_element::<SpanPayload>(
names::SPAN,
"inline content with a display style, a role and kinds",
)?;
b.presentation_element::<ListPayload>(
names::LIST,
"a list: a `label` and an `item` content slot per entry",
)?;
b.presentation_element::<CellsPayload>(
names::CELLS,
"a table of cells: its grid in the payload, a `cell` content slot per entry",
)?;
b.presentation_element::<LinesPayload>(names::LINES, "a sequence of lines")?;
b.presentation_element::<LinePayload>(
names::LINE,
"one line of a `lines` node, with its indentation and alignment",
)?;
b.presentation_element::<VerbatimPayload>(
names::VERBATIM,
"byte-exact content of a verbatim kind (text, code or identifier), inline or as a \
block, with an optional language",
)?;
b.presentation_element::<MathPassthroughPayload>(
names::MATH_PASSTHROUGH,
"mathematics passed through as source text: the formula's content as written, which \
the `math-passthrough` feature stages and nothing in FLM has read",
)?;
b.presentation_element::<MathTextPayload>(
names::MATH_TEXT,
"document content inside a formula: the argument of a text command",
)?;
b.presentation_element::<LinkPayload>(names::LINK, "a link around inline display content")?;
b.presentation_element::<ImagePayload>(names::IMAGE, "an image")?;
b.presentation_element::<UnsupportedPayload>(
names::UNSUPPORTED,
"the childless stand-in for a node the backend cannot render",
)?;
b.presentation_element::<DroppedPayload>(
names::DROPPED,
"the childless mark where a rule left out something it could not place",
)?;
b.presentation_element::<UnknownPayload>(
names::UNKNOWN,
"a macro or environment the parse could not attribute to any feature",
)?;
b.presentation_element::<DecorationPayload>(
names::DECO_RUNIN,
"a decoration at the start of its block (a theorem's heading)",
)?;
b.presentation_element::<DecorationPayload>(
names::DECO_FINAL,
"a decoration closing its block (a proof's closing mark)",
)?;
b.presentation_element::<DecorationPayload>(
names::DECO_MARGIN,
"a decoration set beside the text, level with its decoration mark",
)?;
b.presentation_element::<DecoMarkPayload>(
names::DECO_MARK,
"the childless mark left where the lowering driver moved a decoration out of a \
content slot",
)?;
b.presentation_element::<SubtreePayload>(
names::SUBTREE,
"the position at which another document tree is placed",
)?;
for element in names::DECORATIONS {
b.attach::<dyn Decoration>(element, Arc::new(IsDecoration))?;
}
for element in names::OPAQUE {
b.attach::<dyn OpaqueContent>(element, Arc::new(IsOpaque))?;
}
for element in names::CONTENT_IN_OPAQUE {
b.attach::<dyn ContentInOpaque>(element, Arc::new(IsContentInOpaque))?;
}
Ok(())
}