feat: Add comments
parent
e44590468e
commit
741f15236a
|
@ -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<u8> {
|
||||||
|
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#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<w:comments xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" mc:Ignorable="w14 wp14" />"#
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
mod build_xml;
|
mod build_xml;
|
||||||
|
mod comments;
|
||||||
mod content_types;
|
mod content_types;
|
||||||
mod doc_props;
|
mod doc_props;
|
||||||
mod document;
|
mod document;
|
||||||
|
@ -14,6 +15,7 @@ mod xml_docx;
|
||||||
pub(crate) use build_xml::BuildXML;
|
pub(crate) use build_xml::BuildXML;
|
||||||
pub(crate) use history_id::HistoryId;
|
pub(crate) use history_id::HistoryId;
|
||||||
|
|
||||||
|
pub use comments::*;
|
||||||
pub use content_types::*;
|
pub use content_types::*;
|
||||||
pub use doc_props::*;
|
pub use doc_props::*;
|
||||||
pub use document::*;
|
pub use document::*;
|
||||||
|
@ -33,6 +35,7 @@ pub struct Docx<'a> {
|
||||||
doc_props: DocProps<'a>,
|
doc_props: DocProps<'a>,
|
||||||
styles: Styles,
|
styles: Styles,
|
||||||
document: Document<'a>,
|
document: Document<'a>,
|
||||||
|
comments: Comments,
|
||||||
settings: Settings,
|
settings: Settings,
|
||||||
font_table: FontTable,
|
font_table: FontTable,
|
||||||
}
|
}
|
||||||
|
@ -47,12 +50,14 @@ impl<'a> Default for Docx<'a> {
|
||||||
let document_rels = DocumentRels::new();
|
let document_rels = DocumentRels::new();
|
||||||
let settings = Settings::new();
|
let settings = Settings::new();
|
||||||
let font_table = FontTable::new();
|
let font_table = FontTable::new();
|
||||||
|
let comments = Comments::new();
|
||||||
Docx {
|
Docx {
|
||||||
content_type,
|
content_type,
|
||||||
rels,
|
rels,
|
||||||
doc_props,
|
doc_props,
|
||||||
styles,
|
styles,
|
||||||
document,
|
document,
|
||||||
|
comments,
|
||||||
document_rels,
|
document_rels,
|
||||||
settings,
|
settings,
|
||||||
font_table,
|
font_table,
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod macros;
|
mod macros;
|
||||||
|
|
||||||
|
mod comments;
|
||||||
mod core_properties;
|
mod core_properties;
|
||||||
mod declaration;
|
mod declaration;
|
||||||
mod document;
|
mod document;
|
||||||
|
|
Loading…
Reference in New Issue