diff --git a/crates/idml/src/model/mod.rs b/crates/idml/src/model/mod.rs index b5b685449..ef6fb7a6f 100644 --- a/crates/idml/src/model/mod.rs +++ b/crates/idml/src/model/mod.rs @@ -28,8 +28,8 @@ pub use spread::{ spreads, }; pub use story::{ - Ace, CONTAINERS, Cell, CellOptions, Container, ContentPart, PageReference, Range, Story, StoryAnchor, StoryPreference, Table, TableChild, - TableColumn, TableLayout, TableRow, TextNode, stories, + Ace, CONTAINERS, Cell, CellOptions, Container, ContainerKind, ContentPart, PageReference, Range, Story, StoryAnchor, StoryPreference, Table, + TableChild, TableColumn, TableLayout, TableRow, TextNode, TrackedChangeKind, stories, }; use crate::value::{matrix, nums}; diff --git a/crates/idml/src/model/story.rs b/crates/idml/src/model/story.rs index 98360398a..399e4e241 100644 --- a/crates/idml/src/model/story.rs +++ b/crates/idml/src/model/story.rs @@ -109,6 +109,54 @@ pub struct Container { pub children: Vec, } +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum ContainerKind { + HyperlinkTextSource, + Change, + XMLElement, + CrossReferenceSource, + Footnote, + Note, + EndnoteRange, +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum TrackedChangeKind { + Deleted, + Inserted, + Other, +} + +impl Container { + pub fn to_el(&self) -> El { + with_children(self.values.element(&self.name), &self.children) + } + + pub fn kind(&self) -> ContainerKind { + match self.name.as_str() { + "HyperlinkTextSource" => ContainerKind::HyperlinkTextSource, + "Change" => ContainerKind::Change, + "XMLElement" => ContainerKind::XMLElement, + "CrossReferenceSource" => ContainerKind::CrossReferenceSource, + "Footnote" => ContainerKind::Footnote, + "Note" => ContainerKind::Note, + _ => ContainerKind::EndnoteRange, + } + } + + pub fn self_id(&self) -> Option<&str> { + self.values.self_id() + } + + pub fn change_kind(&self) -> Option { + (self.kind() == ContainerKind::Change).then(|| match self.values.get("ChangeType") { + Some("DeletedText") => TrackedChangeKind::Deleted, + Some("InsertedText" | "MovedText") => TrackedChangeKind::Inserted, + _ => TrackedChangeKind::Other, + }) + } +} + /// A piece of a `Content` element. #[derive(Clone, Debug, PartialEq)] pub enum ContentPart {