1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use derive_more::From;
use strong_xml::{XmlRead, XmlWrite};
use crate::__xml_test_suites;
use crate::document::{Paragraph, Table};
/// Document Body
///
/// This is the main document editing surface.
#[derive(Debug, Default, XmlRead, XmlWrite)]
#[cfg_attr(test, derive(PartialEq))]
#[xml(tag = "w:body")]
pub struct Body<'a> {
/// Specifies the contents of the body of the document.
#[xml(child = "w:p", child = "w:tbl")]
pub content: Vec<BodyContent<'a>>,
}
impl<'a> Body<'a> {
pub fn push<T: Into<BodyContent<'a>>>(&mut self, content: T) -> &mut Self {
self.content.push(content.into());
self
}
// pub fn iter_text(&self) -> impl Iterator<Item = &Cow<'a, str>> {
// self.content
// .iter()
// .filter_map(|content| match content {
// BodyContent::Paragraph(para) => Some(para.iter_text()),
// })
// .flatten()
// }
// pub fn iter_text_mut(&mut self) -> impl Iterator<Item = &mut Cow<'a, str>> {
// self.content
// .iter_mut()
// .filter_map(|content| match content {
// BodyContent::Paragraph(para) => Some(para.iter_text_mut()),
// })
// .flatten()
// }
}
/// A set of elements that can be contained in the body
#[derive(Debug, From, XmlRead, XmlWrite)]
#[cfg_attr(test, derive(PartialEq))]
pub enum BodyContent<'a> {
#[xml(tag = "w:p")]
Paragraph(Paragraph<'a>),
#[xml(tag = "w:tbl")]
Table(Table<'a>),
// SecProp,
}
__xml_test_suites!(
Body,
Body::default(),
r#"<w:body/>"#,
Body {
content: vec![Paragraph::default().into()]
},
r#"<w:body><w:p><w:pPr/></w:p></w:body>"#,
Body {
content: vec![Table::default().into()]
},
r#"<w:body><w:tbl><w:tblPr/></w:tbl></w:body>"#,
);