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 modulemain
parent
74464c82d6
commit
2c8638dcb0
|
@ -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")
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ mod bold_cs;
|
||||||
mod bookmark_end;
|
mod bookmark_end;
|
||||||
mod bookmark_start;
|
mod bookmark_start;
|
||||||
mod br;
|
mod br;
|
||||||
|
mod cant_split;
|
||||||
mod caps;
|
mod caps;
|
||||||
mod cell_margins;
|
mod cell_margins;
|
||||||
mod character_spacing;
|
mod character_spacing;
|
||||||
|
@ -144,6 +145,7 @@ pub use bold_cs::*;
|
||||||
pub use bookmark_end::*;
|
pub use bookmark_end::*;
|
||||||
pub use bookmark_start::*;
|
pub use bookmark_start::*;
|
||||||
pub use br::*;
|
pub use br::*;
|
||||||
|
pub use cant_split::*;
|
||||||
pub use caps::*;
|
pub use caps::*;
|
||||||
pub use cell_margins::*;
|
pub use cell_margins::*;
|
||||||
pub use character_spacing::*;
|
pub use character_spacing::*;
|
||||||
|
|
|
@ -77,6 +77,11 @@ impl TableRow {
|
||||||
self.property = self.property.insert(i);
|
self.property = self.property.insert(i);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn cant_split(mut self) -> TableRow {
|
||||||
|
self.property = self.property.cant_split();
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BuildXML for TableRow {
|
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}}"#
|
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>"#
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,8 @@ pub struct TableRowProperty {
|
||||||
pub del: Option<Delete>,
|
pub del: Option<Delete>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub ins: Option<Insert>,
|
pub ins: Option<Insert>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub cant_split: Option<CantSplit>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TableRowProperty {
|
impl TableRowProperty {
|
||||||
|
@ -65,15 +67,20 @@ impl TableRowProperty {
|
||||||
self.ins = Some(i);
|
self.ins = Some(i);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
pub fn cant_split(mut self) -> Self {
|
||||||
|
self.cant_split = Some(CantSplit::default());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl BuildXML for TableRowProperty {
|
impl BuildXML for TableRowProperty {
|
||||||
fn build(&self) -> Vec<u8> {
|
fn build(&self) -> Vec<u8> {
|
||||||
let mut b = XMLBuilder::new()
|
let mut b = XMLBuilder::new()
|
||||||
.open_table_row_property()
|
.open_table_row_property()
|
||||||
.add_optional_child(&self.del)
|
.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 {
|
if let Some(h) = self.row_height {
|
||||||
b = b.table_row_height(
|
b = b.table_row_height(
|
||||||
&format!("{}", h),
|
&format!("{}", h),
|
||||||
|
@ -97,4 +104,13 @@ mod tests {
|
||||||
let b = TableRowProperty::new().build();
|
let b = TableRowProperty::new().build();
|
||||||
assert_eq!(str::from_utf8(&b).unwrap(), r#"<w:trPr />"#);
|
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>"#
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -400,6 +400,8 @@ impl XMLBuilder {
|
||||||
"w:author",
|
"w:author",
|
||||||
"w:date"
|
"w:date"
|
||||||
);
|
);
|
||||||
|
// cantSplit for table row
|
||||||
|
closed!(cant_split, "w:cantSplit");
|
||||||
|
|
||||||
closed!(bookmark_start, "w:bookmarkStart", "w:id", "w:name");
|
closed!(bookmark_start, "w:bookmarkStart", "w:id", "w:name");
|
||||||
closed!(bookmark_end, "w:bookmarkEnd", "w:id");
|
closed!(bookmark_end, "w:bookmarkEnd", "w:id");
|
||||||
|
|
Loading…
Reference in New Issue