#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NodeId(pub u32);
impl NodeId {
pub const ROOT: NodeId = NodeId(0);
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum Role {
#[default]
Text,
Paragraph,
Heading(u8),
Container,
Image,
Link,
OrderedList,
UnorderedList,
ListItem,
Table,
TableRow,
TableCell,
Sidebar,
Footnote,
Figure,
Inline,
BlockQuote,
Root,
Break,
Rule,
DefinitionList,
DefinitionTerm,
DefinitionDescription,
CodeBlock,
Caption,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct TextRange {
pub start: u32,
pub len: u32,
}
impl TextRange {
pub fn new(start: u32, len: u32) -> Self {
Self { start, len }
}
pub fn is_empty(&self) -> bool {
self.len == 0
}
pub fn end(&self) -> u32 {
self.start + self.len
}
}
use super::style::StyleId;
#[derive(Debug, Clone)]
pub struct Node {
pub role: Role,
pub parent: Option<NodeId>,
pub first_child: Option<NodeId>,
pub next_sibling: Option<NodeId>,
pub style: StyleId,
pub text: TextRange,
}
impl Node {
pub fn new(role: Role) -> Self {
Self {
role,
parent: None,
first_child: None,
next_sibling: None,
style: StyleId::DEFAULT,
text: TextRange::default(),
}
}
pub fn text(range: TextRange) -> Self {
Self {
role: Role::Text,
parent: None,
first_child: None,
next_sibling: None,
style: StyleId::DEFAULT,
text: range,
}
}
}