diff --git a/docx-core/src/documents/elements/level.rs b/docx-core/src/documents/elements/level.rs index 4b47518..2b4f437 100644 --- a/docx-core/src/documents/elements/level.rs +++ b/docx-core/src/documents/elements/level.rs @@ -15,7 +15,7 @@ pub struct Level { pub paragraph_property: ParagraphProperty, pub run_property: RunProperty, pub suffix: LevelSuffixType, - pub pstyle: Option, + pub pstyle: Option, pub level_restart: Option, #[serde(skip_serializing_if = "Option::is_none")] pub is_lgl: Option, @@ -58,7 +58,7 @@ impl Level { } pub fn paragraph_style(mut self, style_id: impl Into) -> Self { - self.pstyle = Some(style_id.into()); + self.pstyle = Some(ParagraphStyle::new(Some(style_id.into()))); self } @@ -134,6 +134,7 @@ impl BuildXML for Level { .add_child(&self.jc) .add_child(&self.paragraph_property) .add_child(&self.run_property) + .add_optional_child(&self.pstyle) .add_optional_child(&self.level_restart) .add_optional_child(&self.is_lgl); @@ -202,4 +203,20 @@ mod tests { "# ); } + #[test] + fn test_level_with_pstyle() { + let b = Level::new( + 1, + Start::new(1), + NumberFormat::new("decimal"), + LevelText::new("%4."), + LevelJc::new("left"), + ) + .paragraph_style("a-style") + .build(); + assert_eq!( + str::from_utf8(&b).unwrap(), + r#""# + ); + } }