docx_rs/documents/
footnotes.rs1use super::Footnote;
2use crate::documents::BuildXML;
3use crate::xml_builder::*;
4use std::io::Write;
5
6use serde::Serialize;
7
8#[derive(Debug, Clone, PartialEq, Serialize, Default)]
9#[serde(rename_all = "camelCase")]
10pub struct Footnotes {
11 pub(crate) footnotes: Vec<Footnote>,
12}
13
14impl Footnotes {
15 pub fn new() -> Self {
16 Self::default()
17 }
18
19 pub(crate) fn add(&mut self, footnotes: Vec<Footnote>) {
20 self.footnotes.extend(footnotes)
21 }
22}
23
24impl BuildXML for Footnotes {
25 fn build_to<W: Write>(
26 &self,
27 stream: xml::writer::EventWriter<W>,
28 ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
29 XMLBuilder::from(stream)
30 .declaration(Some(true))?
31 .open_footnotes()?
32 .add_children(&self.footnotes)?
33 .close()?
34 .into_inner()
35 }
36}
37
38#[cfg(test)]
39mod tests {
40
41 use super::*;
42 #[cfg(test)]
43 use pretty_assertions::assert_eq;
44 use std::str;
45
46 #[test]
47 fn test_footnotes() {
48 let b = Footnotes::new().build();
49 assert_eq!(
50 str::from_utf8(&b).unwrap(),
51 r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:footnotes xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex" xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex" xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink" xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:oel="http://schemas.microsoft.com/office/2019/extlst" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16cex="http://schemas.microsoft.com/office/word/2018/wordml/cex" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w16="http://schemas.microsoft.com/office/word/2018/wordml" xmlns:w16du="http://schemas.microsoft.com/office/word/2023/wordml/word16du" xmlns:w16sdtdh="http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 w16se w16cid w16 w16cex w16sdtdh w16du wp14" />"#
52 );
53 }
54}