pub mod content;
pub use content::*;
use crate::semantic::SemanticRole;
use crate::style::ResolvedStyle;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NodeId(u32);
impl NodeId {
#[must_use]
pub const fn from_raw(index: u32) -> Self {
Self(index)
}
#[must_use]
pub const fn raw(self) -> u32 {
self.0
}
}
impl std::fmt::Display for NodeId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "node#{}", self.0)
}
}
#[derive(Debug, Clone)]
pub struct Node {
pub id: NodeId,
pub content: ContentVariant,
pub style: ResolvedStyle,
pub children: Vec<NodeId>,
pub semantic_role: Option<SemanticRole>,
pub element_id: Option<String>,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum ContentVariant {
Text(TextContent),
Svg(SvgContent),
Math(MathContent),
Image(ImageContent),
Table(TableContent),
Container,
Link(LinkContent),
Form(FormContent),
Footnote(FootnoteContent),
IndexEntry(IndexEntryContent),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn node_id_ordering() {
assert!(NodeId::from_raw(0) < NodeId::from_raw(1));
}
#[test]
fn node_id_display() {
assert_eq!(NodeId::from_raw(42).to_string(), "node#42");
}
}