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
#![allow(unused_must_use)]
use std::{borrow::Cow, io::Write};
use strong_xml::{XmlRead, XmlWrite, XmlResult, XmlWriter};
use crate::{document::Paragraph, schema::{SCHEMA_MAIN, SCHEMA_WORDML_14}};
#[derive(Debug, Default, XmlRead, Clone)]
#[cfg_attr(test, derive(PartialEq))]
#[xml(tag = "w:comments")]
pub struct Comments<'a> {
#[xml(child = "w:comment")]
pub comments: Vec<Comment<'a>>,
}
#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
#[cfg_attr(test, derive(PartialEq))]
#[xml(tag = "w:comment")]
pub struct Comment<'a> {
#[xml(attr = "w:id")]
pub id: Option<isize>,
#[xml(attr = "w:author")]
pub author: Cow<'a, str>,
#[xml(child = "w:p")]
pub content: Paragraph<'a>,
}
impl<'a> XmlWrite for Comments<'a> {
fn to_writer<W: Write>(&self, writer: &mut XmlWriter<W>) -> XmlResult<()> {
let Comments { comments } = self;
log::debug!("[Comments] Started writing.");
let _ = write!(writer.inner, "{}", crate::schema::SCHEMA_XML);
writer.write_element_start("w:comments")?;
writer.write_attribute("xmlns:w", SCHEMA_MAIN)?;
writer.write_attribute("xmlns:w14", SCHEMA_WORDML_14)?;
writer.write_element_end_open()?;
for c in comments {
c.to_writer(writer)?;
}
writer.write_element_end_close("w:comments")?;
log::debug!("[Comments] Finished writing.");
Ok(())
}
}