diff --git a/docx-core/src/documents/comments.rs b/docx-core/src/documents/comments.rs new file mode 100644 index 0000000..31c0db9 --- /dev/null +++ b/docx-core/src/documents/comments.rs @@ -0,0 +1,48 @@ +use super::{Paragraph, Table}; +use crate::documents::BuildXML; +use crate::xml_builder::*; + +#[derive(Debug)] +pub struct Comments {} + +impl Comments { + pub fn new() -> Comments { + Default::default() + } +} + +impl Default for Comments { + fn default() -> Self { + Self {} + } +} + +impl BuildXML for Comments { + fn build(&self) -> Vec { + XMLBuilder::new() + .declaration(Some(true)) + .open_comments() + .close() + .build() + } +} + +#[cfg(test)] +mod tests { + + use super::super::Run; + use super::*; + #[cfg(test)] + use pretty_assertions::assert_eq; + use std::str; + + #[test] + fn test_comments() { + let b = Comments::new().build(); + assert_eq!( + str::from_utf8(&b).unwrap(), + r#" +"# + ); + } +} diff --git a/docx-core/src/documents/mod.rs b/docx-core/src/documents/mod.rs index 421ff86..eb84ddb 100644 --- a/docx-core/src/documents/mod.rs +++ b/docx-core/src/documents/mod.rs @@ -1,4 +1,5 @@ mod build_xml; +mod comments; mod content_types; mod doc_props; mod document; @@ -14,6 +15,7 @@ mod xml_docx; pub(crate) use build_xml::BuildXML; pub(crate) use history_id::HistoryId; +pub use comments::*; pub use content_types::*; pub use doc_props::*; pub use document::*; @@ -33,6 +35,7 @@ pub struct Docx<'a> { doc_props: DocProps<'a>, styles: Styles, document: Document<'a>, + comments: Comments, settings: Settings, font_table: FontTable, } @@ -47,12 +50,14 @@ impl<'a> Default for Docx<'a> { let document_rels = DocumentRels::new(); let settings = Settings::new(); let font_table = FontTable::new(); + let comments = Comments::new(); Docx { content_type, rels, doc_props, styles, document, + comments, document_rels, settings, font_table, diff --git a/docx-core/src/xml_builder/comments.rs b/docx-core/src/xml_builder/comments.rs new file mode 100644 index 0000000..31a2a3d --- /dev/null +++ b/docx-core/src/xml_builder/comments.rs @@ -0,0 +1,49 @@ +use super::XMLBuilder; +use super::XmlEvent; + +impl XMLBuilder { + pub(crate) fn open_comments(mut self) -> Self { + self.writer + .write( + XmlEvent::start_element("w:comments") + .attr("xmlns:o", "urn:schemas-microsoft-com:office:office") + .attr( + "xmlns:r", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships", + ) + .attr("xmlns:v", "urn:schemas-microsoft-com:vml") + .attr( + "xmlns:w", + "http://schemas.openxmlformats.org/wordprocessingml/2006/main", + ) + .attr("xmlns:w10", "urn:schemas-microsoft-com:office:word") + .attr( + "xmlns:wp", + "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", + ) + .attr( + "xmlns:wps", + "http://schemas.microsoft.com/office/word/2010/wordprocessingShape", + ) + .attr( + "xmlns:wpg", + "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup", + ) + .attr( + "xmlns:mc", + "http://schemas.openxmlformats.org/markup-compatibility/2006", + ) + .attr( + "xmlns:wp14", + "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing", + ) + .attr( + "xmlns:w14", + "http://schemas.microsoft.com/office/word/2010/wordml", + ) + .attr("mc:Ignorable", "w14 wp14"), + ) + .expect("should write to buf"); + self + } +} diff --git a/docx-core/src/xml_builder/mod.rs b/docx-core/src/xml_builder/mod.rs index 936ea57..e6a1947 100644 --- a/docx-core/src/xml_builder/mod.rs +++ b/docx-core/src/xml_builder/mod.rs @@ -1,6 +1,7 @@ #[macro_use] mod macros; +mod comments; mod core_properties; mod declaration; mod document;