Support cantSplit for table row (#730)

* Initial cantSplit support: add CantSplit element

* Initial cantSplit support: add cant_split() to XMLBuilder

* Initial cantSplit support: add cant_split() to TableRow element

* Initial cantSplit support: add cant_split() to TableRowProperty element

* Initial cantSplit support: add cant_split module
main
git-noise 2024-06-25 11:43:53 -04:00 committed by GitHub
parent 74464c82d6
commit 2c8638dcb0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 57 additions and 2 deletions

View File

@ -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<u8> {
let b = XMLBuilder::new();
b.cant_split().build()
}
}
impl Serialize for CantSplit {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str("cantSplit")
}
}

View File

@ -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::*;

View File

@ -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#"<w:tr><w:trPr><w:cantSplit /></w:trPr><w:tc><w:tcPr /><w:p w14:paraId="12345678"><w:pPr><w:rPr /></w:pPr></w:p></w:tc></w:tr>"#
);
}
}

View File

@ -19,6 +19,8 @@ pub struct TableRowProperty {
pub del: Option<Delete>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ins: Option<Insert>,
#[serde(skip_serializing_if = "Option::is_none")]
pub cant_split: Option<CantSplit>,
}
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<u8> {
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#"<w:trPr />"#);
}
#[test]
fn test_cant_split() {
let b = TableRowProperty::new().cant_split().build();
assert_eq!(
str::from_utf8(&b).unwrap(),
r#"<w:trPr><w:cantSplit /></w:trPr>"#
);
}
}

View File

@ -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");