diff --git a/docx-core/src/documents/elements/cant_split.rs b/docx-core/src/documents/elements/cant_split.rs new file mode 100644 index 0000000..04133a4 --- /dev/null +++ b/docx-core/src/documents/elements/cant_split.rs @@ -0,0 +1,21 @@ +use serde::{Serialize, Serializer}; + +use crate::{xml_builder::XMLBuilder, BuildXML}; + +#[derive(Debug, Clone, PartialEq, Eq, Default)] +pub struct CantSplit {} +impl BuildXML for CantSplit { + fn build(&self) -> Vec { + let b = XMLBuilder::new(); + b.cant_split().build() + } +} + +impl Serialize for CantSplit { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + serializer.serialize_str("cantSplit") + } +} diff --git a/docx-core/src/documents/elements/mod.rs b/docx-core/src/documents/elements/mod.rs index 9658acd..3801271 100644 --- a/docx-core/src/documents/elements/mod.rs +++ b/docx-core/src/documents/elements/mod.rs @@ -8,6 +8,7 @@ mod bold_cs; mod bookmark_end; mod bookmark_start; mod br; +mod cant_split; mod caps; mod cell_margins; mod character_spacing; @@ -144,6 +145,7 @@ pub use bold_cs::*; pub use bookmark_end::*; pub use bookmark_start::*; pub use br::*; +pub use cant_split::*; pub use caps::*; pub use cell_margins::*; pub use character_spacing::*; diff --git a/docx-core/src/documents/elements/table_row.rs b/docx-core/src/documents/elements/table_row.rs index c52c368..12c34db 100644 --- a/docx-core/src/documents/elements/table_row.rs +++ b/docx-core/src/documents/elements/table_row.rs @@ -77,6 +77,11 @@ impl TableRow { self.property = self.property.insert(i); self } + + pub fn cant_split(mut self) -> TableRow { + self.property = self.property.cant_split(); + self + } } impl BuildXML for TableRow { @@ -130,4 +135,13 @@ mod tests { r#"{"cells":[{"type":"tableCell","data":{"children":[],"property":{"width":null,"borders":null,"gridSpan":null,"verticalMerge":null,"verticalAlign":null,"textDirection":null,"shading":null},"hasNumbering":false}}],"hasNumbering":false,"property":{"gridAfter":null,"widthAfter":null,"gridBefore":null,"widthBefore":null}}"# ); } + + #[test] + fn test_row_cant_split() { + let b = TableRow::new(vec![TableCell::new()]).cant_split().build(); + assert_eq!( + str::from_utf8(&b).unwrap(), + r#""# + ); + } } diff --git a/docx-core/src/documents/elements/table_row_property.rs b/docx-core/src/documents/elements/table_row_property.rs index 08f31e8..f4e6dcc 100644 --- a/docx-core/src/documents/elements/table_row_property.rs +++ b/docx-core/src/documents/elements/table_row_property.rs @@ -19,6 +19,8 @@ pub struct TableRowProperty { pub del: Option, #[serde(skip_serializing_if = "Option::is_none")] pub ins: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub cant_split: Option, } impl TableRowProperty { @@ -65,15 +67,20 @@ impl TableRowProperty { self.ins = Some(i); self } -} + pub fn cant_split(mut self) -> Self { + self.cant_split = Some(CantSplit::default()); + self + } +} impl BuildXML for TableRowProperty { fn build(&self) -> Vec { let mut b = XMLBuilder::new() .open_table_row_property() .add_optional_child(&self.del) - .add_optional_child(&self.ins); + .add_optional_child(&self.ins) + .add_optional_child(&self.cant_split); if let Some(h) = self.row_height { b = b.table_row_height( &format!("{}", h), @@ -97,4 +104,13 @@ mod tests { let b = TableRowProperty::new().build(); assert_eq!(str::from_utf8(&b).unwrap(), r#""#); } + + #[test] + fn test_cant_split() { + let b = TableRowProperty::new().cant_split().build(); + assert_eq!( + str::from_utf8(&b).unwrap(), + r#""# + ); + } } diff --git a/docx-core/src/xml_builder/elements.rs b/docx-core/src/xml_builder/elements.rs index 8b041fa..f923ac6 100644 --- a/docx-core/src/xml_builder/elements.rs +++ b/docx-core/src/xml_builder/elements.rs @@ -400,6 +400,8 @@ impl XMLBuilder { "w:author", "w:date" ); + // cantSplit for table row + closed!(cant_split, "w:cantSplit"); closed!(bookmark_start, "w:bookmarkStart", "w:id", "w:name"); closed!(bookmark_end, "w:bookmarkEnd", "w:id");