Support custom props (#307)
* faet: Add custom props * feat: Support custom in js * feat: Support reader * update snapsmain
parent
21811daf6f
commit
5bcb009100
|
@ -0,0 +1,12 @@
|
||||||
|
use docx_rs::*;
|
||||||
|
|
||||||
|
pub fn main() -> Result<(), DocxError> {
|
||||||
|
let path = std::path::Path::new("./output/custom_property.docx");
|
||||||
|
let file = std::fs::File::create(&path).unwrap();
|
||||||
|
Docx::new()
|
||||||
|
.add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello")))
|
||||||
|
.custom_property("hello", "world")
|
||||||
|
.build()
|
||||||
|
.pack(file)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -4,7 +4,7 @@ use std::fs::File;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let mut file = File::open("./fixtures/div/div.docx").unwrap();
|
let mut file = File::open("./fixtures/custom/custom.docx").unwrap();
|
||||||
let mut buf = vec![];
|
let mut buf = vec![];
|
||||||
file.read_to_end(&mut buf).unwrap();
|
file.read_to_end(&mut buf).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,10 @@ impl ContentTypes {
|
||||||
"application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml"
|
"application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml"
|
||||||
.to_owned(),
|
.to_owned(),
|
||||||
);
|
);
|
||||||
|
self.types.insert(
|
||||||
|
"/docProps/custom.xml".to_owned(),
|
||||||
|
"application/vnd.openxmlformats-officedocument.custom-properties+xml".to_owned(),
|
||||||
|
);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use crate::documents::BuildXML;
|
||||||
|
use crate::xml_builder::*;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Serialize, Default)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct CustomProps {
|
||||||
|
pub properties: std::collections::HashMap<String, String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CustomProps {
|
||||||
|
pub(crate) fn new() -> Self {
|
||||||
|
Self::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_custom_property(mut self, name: impl Into<String>, item: impl Into<String>) -> Self {
|
||||||
|
self.properties.insert(name.into(), item.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BuildXML for CustomProps {
|
||||||
|
fn build(&self) -> Vec<u8> {
|
||||||
|
let b = XMLBuilder::new();
|
||||||
|
let mut base = b.declaration(Some(true)).open_custom_properties(
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/custom-properties",
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes",
|
||||||
|
);
|
||||||
|
|
||||||
|
for (i, (key, item)) in self.properties.iter().enumerate() {
|
||||||
|
base = base
|
||||||
|
.open_property(
|
||||||
|
"{D5CDD505-2E9C-101B-9397-08002B2CF9AE}",
|
||||||
|
// I can not found spec about this id.
|
||||||
|
// It is invalid if pid started by 1....
|
||||||
|
&format!("{}", i + 2),
|
||||||
|
key,
|
||||||
|
)
|
||||||
|
.lpwstr(item)
|
||||||
|
.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
base.close().build()
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,10 @@
|
||||||
mod app;
|
mod app;
|
||||||
mod core;
|
mod core;
|
||||||
|
mod custom;
|
||||||
|
|
||||||
pub use self::app::*;
|
pub use self::app::*;
|
||||||
pub use self::core::*;
|
pub use self::core::*;
|
||||||
|
pub use self::custom::*;
|
||||||
|
|
||||||
use crate::documents::BuildXML;
|
use crate::documents::BuildXML;
|
||||||
|
|
||||||
|
@ -13,13 +15,15 @@ use serde::Serialize;
|
||||||
pub struct DocProps {
|
pub struct DocProps {
|
||||||
pub app: AppProps,
|
pub app: AppProps,
|
||||||
pub core: CoreProps,
|
pub core: CoreProps,
|
||||||
|
pub custom: CustomProps,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DocProps {
|
impl DocProps {
|
||||||
pub(crate) fn new(core_config: CorePropsConfig) -> DocProps {
|
pub(crate) fn new(core_config: CorePropsConfig) -> DocProps {
|
||||||
let app = AppProps::new();
|
let app = AppProps::new();
|
||||||
let core = CoreProps::new(core_config);
|
let core = CoreProps::new(core_config);
|
||||||
DocProps { app, core }
|
let custom = CustomProps::new();
|
||||||
|
DocProps { app, core, custom }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn created_at(mut self, date: &str) -> Self {
|
pub fn created_at(mut self, date: &str) -> Self {
|
||||||
|
@ -32,10 +36,16 @@ impl DocProps {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn custom_property(mut self, name: impl Into<String>, item: impl Into<String>) -> Self {
|
||||||
|
self.custom = self.custom.add_custom_property(name.into(), item.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn build(&self) -> XMLDocProps {
|
pub(crate) fn build(&self) -> XMLDocProps {
|
||||||
XMLDocProps {
|
XMLDocProps {
|
||||||
app: self.app.build(),
|
app: self.app.build(),
|
||||||
core: self.core.build(),
|
core: self.core.build(),
|
||||||
|
custom: self.custom.build(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,4 +54,5 @@ impl DocProps {
|
||||||
pub struct XMLDocProps {
|
pub struct XMLDocProps {
|
||||||
pub app: Vec<u8>,
|
pub app: Vec<u8>,
|
||||||
pub core: Vec<u8>,
|
pub core: Vec<u8>,
|
||||||
|
pub custom: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,14 +83,14 @@ impl Default for Docx {
|
||||||
Docx {
|
Docx {
|
||||||
content_type,
|
content_type,
|
||||||
rels,
|
rels,
|
||||||
|
document_rels,
|
||||||
doc_props,
|
doc_props,
|
||||||
styles,
|
styles,
|
||||||
document,
|
document,
|
||||||
comments,
|
comments,
|
||||||
document_rels,
|
numberings,
|
||||||
settings,
|
settings,
|
||||||
font_table,
|
font_table,
|
||||||
numberings,
|
|
||||||
media,
|
media,
|
||||||
header,
|
header,
|
||||||
comments_extended,
|
comments_extended,
|
||||||
|
@ -215,6 +215,11 @@ impl Docx {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn custom_property(mut self, name: impl Into<String>, item: impl Into<String>) -> Self {
|
||||||
|
self.doc_props = self.doc_props.custom_property(name, item);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn doc_id(mut self, id: &str) -> Self {
|
pub fn doc_id(mut self, id: &str) -> Self {
|
||||||
self.settings = self.settings.doc_id(id);
|
self.settings = self.settings.doc_id(id);
|
||||||
self
|
self
|
||||||
|
|
|
@ -30,6 +30,12 @@ impl Rels {
|
||||||
"rId3".to_owned(),
|
"rId3".to_owned(),
|
||||||
"word/document.xml".to_owned(),
|
"word/document.xml".to_owned(),
|
||||||
));
|
));
|
||||||
|
self.rels.push((
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties"
|
||||||
|
.to_owned(),
|
||||||
|
"rId4".to_owned(),
|
||||||
|
"docProps/custom.xml".to_owned(),
|
||||||
|
));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,6 +92,7 @@ mod tests {
|
||||||
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml" />
|
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml" />
|
||||||
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml" />
|
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml" />
|
||||||
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml" />
|
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml" />
|
||||||
|
<Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties" Target="docProps/custom.xml" />
|
||||||
</Relationships>"#
|
</Relationships>"#
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
use std::io::Read;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use xml::reader::{EventReader, XmlEvent};
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
impl FromXML for CustomProps {
|
||||||
|
fn from_xml<R: Read>(reader: R) -> Result<Self, ReaderError> {
|
||||||
|
let mut r = EventReader::new(reader);
|
||||||
|
// TODO: Fow now, support only string.
|
||||||
|
let mut props = CustomProps::new();
|
||||||
|
loop {
|
||||||
|
let e = r.next();
|
||||||
|
match e {
|
||||||
|
Ok(XmlEvent::StartElement {
|
||||||
|
name, attributes, ..
|
||||||
|
}) => {
|
||||||
|
if let Ok(XMLElement::Property) = XMLElement::from_str(&name.local_name) {
|
||||||
|
if let Some(key) = read_name(&attributes) {
|
||||||
|
loop {
|
||||||
|
let e = r.next();
|
||||||
|
match e {
|
||||||
|
Ok(XmlEvent::StartElement { name, .. }) => {
|
||||||
|
// TODO: Fow now, support only string.
|
||||||
|
if let Ok(VtXMLElement::Lpwstr) =
|
||||||
|
VtXMLElement::from_str(&name.local_name)
|
||||||
|
{
|
||||||
|
let e = r.next();
|
||||||
|
if let Ok(XmlEvent::Characters(c)) = e {
|
||||||
|
props = props.add_custom_property(&key, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(XmlEvent::EndElement { name, .. }) => {
|
||||||
|
if let Ok(XMLElement::Property) =
|
||||||
|
XMLElement::from_str(&name.local_name)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(XmlEvent::EndDocument { .. }) => {
|
||||||
|
return Ok(props);
|
||||||
|
}
|
||||||
|
Err(_) => return Err(ReaderError::XMLReadError),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ mod comment;
|
||||||
mod comment_extended;
|
mod comment_extended;
|
||||||
mod comments;
|
mod comments;
|
||||||
mod comments_extended;
|
mod comments_extended;
|
||||||
|
mod custom_properties;
|
||||||
mod delete;
|
mod delete;
|
||||||
mod div;
|
mod div;
|
||||||
mod doc_defaults;
|
mod doc_defaults;
|
||||||
|
@ -63,6 +64,8 @@ pub use xml_element::*;
|
||||||
// 2006
|
// 2006
|
||||||
const DOC_RELATIONSHIP_TYPE: &str =
|
const DOC_RELATIONSHIP_TYPE: &str =
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";
|
||||||
|
const CUSTOM_PROPERTIES_TYPE: &str =
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties";
|
||||||
const STYLE_RELATIONSHIP_TYPE: &str =
|
const STYLE_RELATIONSHIP_TYPE: &str =
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles";
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles";
|
||||||
const NUMBERING_RELATIONSHIP_TYPE: &str =
|
const NUMBERING_RELATIONSHIP_TYPE: &str =
|
||||||
|
@ -78,6 +81,7 @@ const COMMENTS_EXTENDED_TYPE: &str =
|
||||||
"http://schemas.microsoft.com/office/2011/relationships/commentsExtended";
|
"http://schemas.microsoft.com/office/2011/relationships/commentsExtended";
|
||||||
|
|
||||||
pub fn read_docx(buf: &[u8]) -> Result<Docx, ReaderError> {
|
pub fn read_docx(buf: &[u8]) -> Result<Docx, ReaderError> {
|
||||||
|
let mut docx = Docx::new();
|
||||||
let cur = Cursor::new(buf);
|
let cur = Cursor::new(buf);
|
||||||
let mut archive = zip::ZipArchive::new(cur)?;
|
let mut archive = zip::ZipArchive::new(cur)?;
|
||||||
// First, the content type for relationship parts and the Main Document part
|
// First, the content type for relationship parts and the Main Document part
|
||||||
|
@ -105,6 +109,15 @@ pub fn read_docx(buf: &[u8]) -> Result<Docx, ReaderError> {
|
||||||
"word/document.xml".to_owned()
|
"word/document.xml".to_owned()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if let Some(custom_props) = rels.find_target(CUSTOM_PROPERTIES_TYPE) {
|
||||||
|
let data = read_zip(&mut archive, &custom_props.2);
|
||||||
|
if let Ok(data) = data {
|
||||||
|
if let Ok(custom) = CustomProps::from_xml(&data[..]) {
|
||||||
|
docx.doc_props.custom = custom;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let rels = read_document_rels(&mut archive, &document_path)?;
|
let rels = read_document_rels(&mut archive, &document_path)?;
|
||||||
|
|
||||||
// Read commentsExtended
|
// Read commentsExtended
|
||||||
|
@ -177,7 +190,7 @@ pub fn read_docx(buf: &[u8]) -> Result<Docx, ReaderError> {
|
||||||
let data = read_zip(&mut archive, &document_path)?;
|
let data = read_zip(&mut archive, &document_path)?;
|
||||||
Document::from_xml(&data[..])?
|
Document::from_xml(&data[..])?
|
||||||
};
|
};
|
||||||
let mut docx = Docx::new().document(document);
|
docx = docx.document(document);
|
||||||
|
|
||||||
// store comments to paragraphs.
|
// store comments to paragraphs.
|
||||||
if !comments.inner().is_empty() {
|
if !comments.inner().is_empty() {
|
||||||
|
|
|
@ -61,6 +61,7 @@ pub enum XMLElement {
|
||||||
CommentRangeStart,
|
CommentRangeStart,
|
||||||
CommentRangeEnd,
|
CommentRangeEnd,
|
||||||
CommentExtended,
|
CommentExtended,
|
||||||
|
Property,
|
||||||
CommentsExtended,
|
CommentsExtended,
|
||||||
VAlign,
|
VAlign,
|
||||||
Shading,
|
Shading,
|
||||||
|
@ -193,6 +194,11 @@ pub enum VXMLElement {
|
||||||
Unsupported,
|
Unsupported,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum VtXMLElement {
|
||||||
|
Lpwstr,
|
||||||
|
Unsupported,
|
||||||
|
}
|
||||||
|
|
||||||
impl FromStr for XMLElement {
|
impl FromStr for XMLElement {
|
||||||
type Err = ();
|
type Err = ();
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
@ -236,6 +242,7 @@ impl FromStr for XMLElement {
|
||||||
"commentEx" => Ok(XMLElement::CommentExtended),
|
"commentEx" => Ok(XMLElement::CommentExtended),
|
||||||
"commentsEx" => Ok(XMLElement::CommentsExtended),
|
"commentsEx" => Ok(XMLElement::CommentsExtended),
|
||||||
"shd" => Ok(XMLElement::Shading),
|
"shd" => Ok(XMLElement::Shading),
|
||||||
|
"property" => Ok(XMLElement::Property),
|
||||||
"tbl" => Ok(XMLElement::Table),
|
"tbl" => Ok(XMLElement::Table),
|
||||||
"tblPr" => Ok(XMLElement::TableProperty),
|
"tblPr" => Ok(XMLElement::TableProperty),
|
||||||
"tr" => Ok(XMLElement::TableRow),
|
"tr" => Ok(XMLElement::TableRow),
|
||||||
|
@ -404,6 +411,16 @@ impl FromStr for VXMLElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl FromStr for VtXMLElement {
|
||||||
|
type Err = ();
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
match s {
|
||||||
|
"lpwstr" => Ok(VtXMLElement::Lpwstr),
|
||||||
|
_ => Ok(VtXMLElement::Unsupported),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait ElementReader {
|
pub trait ElementReader {
|
||||||
fn read<R: Read>(r: &mut EventReader<R>, attrs: &[OwnedAttribute]) -> Result<Self, ReaderError>
|
fn read<R: Read>(r: &mut EventReader<R>, attrs: &[OwnedAttribute]) -> Result<Self, ReaderError>
|
||||||
where
|
where
|
||||||
|
|
|
@ -0,0 +1,214 @@
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
use std::io::Read;
|
||||||
|
use xml::attribute::OwnedAttribute;
|
||||||
|
use xml::reader::{EventReader, XmlEvent};
|
||||||
|
|
||||||
|
use crate::documents::BuildXML;
|
||||||
|
use crate::reader::{FromXML, ReaderError};
|
||||||
|
use crate::xml_builder::*;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
pub fn read_content_type(attrs: &[OwnedAttribute]) -> Option<String> {
|
||||||
|
for a in attrs {
|
||||||
|
let local_name = &a.name.local_name;
|
||||||
|
if local_name == "contentType" {
|
||||||
|
return Some(a.value.to_owned());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_xml(xml: &str) -> Result<Docx, ReaderError> {
|
||||||
|
let mut parser = EventReader::new(xml.as_bytes());
|
||||||
|
// let rels = Rels::from_xml(&data[..])?
|
||||||
|
for e in parser {
|
||||||
|
let mut rels = Rels::new();
|
||||||
|
match e {
|
||||||
|
Ok(XmlEvent::StartElement {
|
||||||
|
attributes, name, ..
|
||||||
|
}) => {
|
||||||
|
if let (Some("pkg"), "part") = (name.prefix.as_deref(), name.local_name.as_ref()) {
|
||||||
|
if let Some(content_type) = read_content_type(&attributes) {
|
||||||
|
match content_type.as_ref() {
|
||||||
|
RELATIONSHIPS_CONTENT_TYPE => {
|
||||||
|
if let Ok(r) = Rels::read(&mut parser, &attributes) {
|
||||||
|
rels = r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// let e = XMLElement::from_str(&name.local_name).unwrap();
|
||||||
|
// match e {
|
||||||
|
// XMLElement::Tab => {}
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(XmlEvent::EndElement { .. }) => {}
|
||||||
|
Err(_) => {}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
todo!();
|
||||||
|
|
||||||
|
// Ok(s);
|
||||||
|
// todo!();
|
||||||
|
// // First, the content type for relationship parts and the Main Document part
|
||||||
|
// // (the only required part) must be defined (physically located at /[Content_Types].xml in the package)
|
||||||
|
// // let _content_types = {
|
||||||
|
// // let data = read_zip(&mut archive, "[Content_Types].xml")?;
|
||||||
|
// // ContentTypes::from_xml(&data[..])?
|
||||||
|
// // };
|
||||||
|
//
|
||||||
|
// // Next, the single required relationship (the package-level relationship to the Main Document part)
|
||||||
|
// // must be defined (physically located at /_rels/.rels in the package)
|
||||||
|
// let rels = {
|
||||||
|
// let data = read_zip(&mut archive, "_rels/.rels")?;
|
||||||
|
// Rels::from_xml(&data[..])?
|
||||||
|
// };
|
||||||
|
// // Finally, the minimum content for the Main Document part must be defined
|
||||||
|
// // (physically located at /document.xml in the package):
|
||||||
|
// let main_rel = rels
|
||||||
|
// .find_target(DOC_RELATIONSHIP_TYPE)
|
||||||
|
// .ok_or(ReaderError::DocumentNotFoundError);
|
||||||
|
//
|
||||||
|
// let document_path = if let Ok(rel) = main_rel {
|
||||||
|
// rel.2.clone()
|
||||||
|
// } else {
|
||||||
|
// "word/document.xml".to_owned()
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// let rels = read_document_rels(&mut archive, &document_path)?;
|
||||||
|
//
|
||||||
|
// // Read commentsExtended
|
||||||
|
// let comments_extended_path = rels.find_target_path(COMMENTS_EXTENDED_TYPE);
|
||||||
|
// let comments_extended = if let Some(comments_extended_path) = comments_extended_path {
|
||||||
|
// let data = read_zip(
|
||||||
|
// &mut archive,
|
||||||
|
// comments_extended_path
|
||||||
|
// .to_str()
|
||||||
|
// .expect("should have comments extended."),
|
||||||
|
// );
|
||||||
|
// if let Ok(data) = data {
|
||||||
|
// CommentsExtended::from_xml(&data[..])?
|
||||||
|
// } else {
|
||||||
|
// CommentsExtended::default()
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// CommentsExtended::default()
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// // Read comments
|
||||||
|
// let comments_path = rels.find_target_path(COMMENTS_TYPE);
|
||||||
|
// let comments = if let Some(comments_path) = comments_path {
|
||||||
|
// let data = read_zip(
|
||||||
|
// &mut archive,
|
||||||
|
// comments_path.to_str().expect("should have comments."),
|
||||||
|
// );
|
||||||
|
// if let Ok(data) = data {
|
||||||
|
// let mut comments = Comments::from_xml(&data[..])?.into_inner();
|
||||||
|
// for i in 0..comments.len() {
|
||||||
|
// let c = &comments[i];
|
||||||
|
// let extended = comments_extended.children.iter().find(|ex| {
|
||||||
|
// for child in &c.children {
|
||||||
|
// if let CommentChild::Paragraph(p) = child {
|
||||||
|
// if ex.paragraph_id == p.id {
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// false
|
||||||
|
// });
|
||||||
|
// if let Some(CommentExtended {
|
||||||
|
// parent_paragraph_id: Some(parent_paragraph_id),
|
||||||
|
// ..
|
||||||
|
// }) = extended
|
||||||
|
// {
|
||||||
|
// if let Some(parent_comment) = comments.iter().find(|c| {
|
||||||
|
// for child in &c.children {
|
||||||
|
// if let CommentChild::Paragraph(p) = child {
|
||||||
|
// if &p.id == parent_paragraph_id {
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// false
|
||||||
|
// }) {
|
||||||
|
// comments[i].parent_comment_id = Some(parent_comment.id);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// Comments { comments }
|
||||||
|
// } else {
|
||||||
|
// Comments::default()
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// Comments::default()
|
||||||
|
// };
|
||||||
|
|
||||||
|
/*
|
||||||
|
let document = {
|
||||||
|
let data = read_zip(&mut archive, &document_path)?;
|
||||||
|
Document::from_xml(&data[..])?
|
||||||
|
};
|
||||||
|
let mut docx = Docx::new().document(document);
|
||||||
|
|
||||||
|
// store comments to paragraphs.
|
||||||
|
if !comments.inner().is_empty() {
|
||||||
|
docx.store_comments(comments.inner());
|
||||||
|
docx = docx.comments(comments);
|
||||||
|
docx = docx.comments_extended(comments_extended);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read document relationships
|
||||||
|
// Read styles
|
||||||
|
let style_path = rels.find_target_path(STYLE_RELATIONSHIP_TYPE);
|
||||||
|
if let Some(style_path) = style_path {
|
||||||
|
let data = read_zip(
|
||||||
|
&mut archive,
|
||||||
|
style_path.to_str().expect("should have styles"),
|
||||||
|
)?;
|
||||||
|
let styles = Styles::from_xml(&data[..])?;
|
||||||
|
docx = docx.styles(styles);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read numberings
|
||||||
|
let num_path = rels.find_target_path(NUMBERING_RELATIONSHIP_TYPE);
|
||||||
|
if let Some(num_path) = num_path {
|
||||||
|
let data = read_zip(
|
||||||
|
&mut archive,
|
||||||
|
num_path.to_str().expect("should have numberings"),
|
||||||
|
)?;
|
||||||
|
let nums = Numberings::from_xml(&data[..])?;
|
||||||
|
docx = docx.numberings(nums);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read settings
|
||||||
|
let settings_path = rels.find_target_path(SETTINGS_TYPE);
|
||||||
|
if let Some(settings_path) = settings_path {
|
||||||
|
let data = read_zip(
|
||||||
|
&mut archive,
|
||||||
|
settings_path.to_str().expect("should have settings"),
|
||||||
|
)?;
|
||||||
|
let settings = Settings::from_xml(&data[..])?;
|
||||||
|
docx = docx.settings(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read web settings
|
||||||
|
let web_settings_path = rels.find_target_path(WEB_SETTINGS_TYPE);
|
||||||
|
dbg!(&web_settings_path);
|
||||||
|
if let Some(web_settings_path) = web_settings_path {
|
||||||
|
let data = read_zip(
|
||||||
|
&mut archive,
|
||||||
|
web_settings_path
|
||||||
|
.to_str()
|
||||||
|
.expect("should have web settings"),
|
||||||
|
)?;
|
||||||
|
let web_settings = WebSettings::from_xml(&data[..])?;
|
||||||
|
docx = docx.web_settings(web_settings);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
// Ok(docx)
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
use super::XMLBuilder;
|
||||||
|
use super::XmlEvent;
|
||||||
|
|
||||||
|
impl XMLBuilder {
|
||||||
|
open!(open_custom_properties, "Properties", "xmlns", "xmlns:vt");
|
||||||
|
open!(open_property, "property", "fmtid", "pid", "name");
|
||||||
|
closed_with_child!(lpwstr, "vt:lpwstr");
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ mod macros;
|
||||||
mod comments;
|
mod comments;
|
||||||
mod comments_extended;
|
mod comments_extended;
|
||||||
mod core_properties;
|
mod core_properties;
|
||||||
|
mod custom_properties;
|
||||||
mod declaration;
|
mod declaration;
|
||||||
mod document;
|
mod document;
|
||||||
mod drawing;
|
mod drawing;
|
||||||
|
@ -15,6 +16,7 @@ mod pic;
|
||||||
mod properties;
|
mod properties;
|
||||||
mod relationship;
|
mod relationship;
|
||||||
mod settings;
|
mod settings;
|
||||||
|
|
||||||
mod styles;
|
mod styles;
|
||||||
|
|
||||||
use crate::BuildXML;
|
use crate::BuildXML;
|
||||||
|
|
|
@ -27,6 +27,8 @@ where
|
||||||
zip.write_all(&xml.doc_props.app)?;
|
zip.write_all(&xml.doc_props.app)?;
|
||||||
zip.start_file("docProps/core.xml", options)?;
|
zip.start_file("docProps/core.xml", options)?;
|
||||||
zip.write_all(&xml.doc_props.core)?;
|
zip.write_all(&xml.doc_props.core)?;
|
||||||
|
zip.start_file("docProps/custom.xml", options)?;
|
||||||
|
zip.write_all(&xml.doc_props.custom)?;
|
||||||
zip.start_file("word/_rels/document.xml.rels", options)?;
|
zip.start_file("word/_rels/document.xml.rels", options)?;
|
||||||
zip.write_all(&xml.document_rels)?;
|
zip.write_all(&xml.document_rels)?;
|
||||||
zip.start_file("word/document.xml", options)?;
|
zip.start_file("word/document.xml", options)?;
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,7 @@
|
||||||
export class DocProps {
|
export class DocProps {
|
||||||
_createdAt: string | null = null;
|
_createdAt: string | null = null;
|
||||||
_updatedAt: string | null = null;
|
_updatedAt: string | null = null;
|
||||||
|
_customProperties: { [name: string]: string } = {};
|
||||||
|
|
||||||
createdAt(date: string) {
|
createdAt(date: string) {
|
||||||
this._createdAt = date;
|
this._createdAt = date;
|
||||||
|
@ -11,4 +12,9 @@ export class DocProps {
|
||||||
this._updatedAt = date;
|
this._updatedAt = date;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
customProperty(name: string, item: string) {
|
||||||
|
this._customProperties[name] = item;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,6 +131,11 @@ export class Docx {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
customProperty(name: string, item: string) {
|
||||||
|
this.docProps.customProperty(name, item);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
updatedAt(date: string) {
|
updatedAt(date: string) {
|
||||||
this.docProps.updatedAt(date);
|
this.docProps.updatedAt(date);
|
||||||
return this;
|
return this;
|
||||||
|
@ -845,6 +850,14 @@ export class Docx {
|
||||||
docx = docx.updated_at(this.docProps._updatedAt);
|
docx = docx.updated_at(this.docProps._updatedAt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Object.entries(this.docProps._customProperties).forEach(([key, item]) => {
|
||||||
|
docx = docx.custom_property(key, item);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (this.docProps._updatedAt) {
|
||||||
|
docx = docx.updated_at(this.docProps._updatedAt);
|
||||||
|
}
|
||||||
|
|
||||||
return docx;
|
return docx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,9 @@ export type DocxJSON = {
|
||||||
title: string | null;
|
title: string | null;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
custom: {
|
||||||
|
[key: string]: string;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
styles: StylesJSON;
|
styles: StylesJSON;
|
||||||
document: DocumentJSON;
|
document: DocumentJSON;
|
||||||
|
|
|
@ -53,6 +53,11 @@ impl Docx {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn custom_property(mut self, name: &str, item: &str) -> Self {
|
||||||
|
self.0.doc_props = self.0.doc_props.custom_property(name, item);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn doc_id(mut self, id: &str) -> Docx {
|
pub fn doc_id(mut self, id: &str) -> Docx {
|
||||||
self.0 = self.0.doc_id(id);
|
self.0 = self.0.doc_id(id);
|
||||||
self
|
self
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`reader should read div docx 1`] = `
|
exports[`reader should read custom docx 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"comments": Object {
|
"comments": Object {
|
||||||
"comments": Array [],
|
"comments": Array [],
|
||||||
|
@ -13,6 +13,7 @@ Object {
|
||||||
"/_rels/.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
"/_rels/.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
||||||
"/docProps/app.xml": "application/vnd.openxmlformats-officedocument.extended-properties+xml",
|
"/docProps/app.xml": "application/vnd.openxmlformats-officedocument.extended-properties+xml",
|
||||||
"/docProps/core.xml": "application/vnd.openxmlformats-package.core-properties+xml",
|
"/docProps/core.xml": "application/vnd.openxmlformats-package.core-properties+xml",
|
||||||
|
"/docProps/custom.xml": "application/vnd.openxmlformats-officedocument.custom-properties+xml",
|
||||||
"/word/_rels/document.xml.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
"/word/_rels/document.xml.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
||||||
"/word/comments.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",
|
"/word/comments.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",
|
||||||
"/word/commentsExtended.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",
|
"/word/commentsExtended.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",
|
||||||
|
@ -39,6 +40,369 @@ Object {
|
||||||
"title": null,
|
"title": null,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"custom": Object {
|
||||||
|
"properties": Object {
|
||||||
|
"hello": "world",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"document": Object {
|
||||||
|
"children": Array [
|
||||||
|
Object {
|
||||||
|
"data": Object {
|
||||||
|
"children": Array [
|
||||||
|
Object {
|
||||||
|
"data": Object {
|
||||||
|
"children": Array [
|
||||||
|
Object {
|
||||||
|
"data": Object {
|
||||||
|
"preserveSpace": true,
|
||||||
|
"text": "Hello",
|
||||||
|
},
|
||||||
|
"type": "text",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"runProperty": Object {
|
||||||
|
"bold": null,
|
||||||
|
"boldCs": null,
|
||||||
|
"color": null,
|
||||||
|
"del": null,
|
||||||
|
"fonts": null,
|
||||||
|
"highlight": null,
|
||||||
|
"ins": null,
|
||||||
|
"italic": null,
|
||||||
|
"italicCs": null,
|
||||||
|
"spacing": null,
|
||||||
|
"sz": null,
|
||||||
|
"szCs": null,
|
||||||
|
"textBorder": null,
|
||||||
|
"underline": null,
|
||||||
|
"vanish": null,
|
||||||
|
"vertAlign": null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"type": "run",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"hasNumbering": false,
|
||||||
|
"id": "00000001",
|
||||||
|
"property": Object {
|
||||||
|
"alignment": null,
|
||||||
|
"divId": null,
|
||||||
|
"indent": null,
|
||||||
|
"keepLines": false,
|
||||||
|
"keepNext": false,
|
||||||
|
"lineHeight": null,
|
||||||
|
"numberingProperty": null,
|
||||||
|
"pageBreakBefore": false,
|
||||||
|
"runProperty": Object {
|
||||||
|
"bold": null,
|
||||||
|
"boldCs": null,
|
||||||
|
"color": null,
|
||||||
|
"del": null,
|
||||||
|
"fonts": null,
|
||||||
|
"highlight": null,
|
||||||
|
"ins": null,
|
||||||
|
"italic": null,
|
||||||
|
"italicCs": null,
|
||||||
|
"spacing": null,
|
||||||
|
"sz": null,
|
||||||
|
"szCs": null,
|
||||||
|
"textBorder": null,
|
||||||
|
"underline": null,
|
||||||
|
"vanish": null,
|
||||||
|
"vertAlign": null,
|
||||||
|
},
|
||||||
|
"style": null,
|
||||||
|
"windowControl": false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"type": "paragraph",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"hasNumbering": false,
|
||||||
|
"sectionProperty": Object {
|
||||||
|
"columns": 425,
|
||||||
|
"docGrid": Object {
|
||||||
|
"charSpace": null,
|
||||||
|
"gridType": "lines",
|
||||||
|
"linePitch": 360,
|
||||||
|
},
|
||||||
|
"headerReference": Object {
|
||||||
|
"headerType": "default",
|
||||||
|
"id": "rId4",
|
||||||
|
},
|
||||||
|
"pageMargin": Object {
|
||||||
|
"bottom": 1701,
|
||||||
|
"footer": 992,
|
||||||
|
"gutter": 0,
|
||||||
|
"header": 851,
|
||||||
|
"left": 1701,
|
||||||
|
"right": 1701,
|
||||||
|
"top": 1985,
|
||||||
|
},
|
||||||
|
"pageSize": Object {
|
||||||
|
"h": 16838,
|
||||||
|
"orient": null,
|
||||||
|
"w": 11906,
|
||||||
|
},
|
||||||
|
"sectionType": null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"documentRels": Object {
|
||||||
|
"hasComments": false,
|
||||||
|
"hasNumberings": false,
|
||||||
|
"imageIds": Array [],
|
||||||
|
},
|
||||||
|
"fontTable": Object {},
|
||||||
|
"header": Object {
|
||||||
|
"children": Array [],
|
||||||
|
},
|
||||||
|
"media": Array [],
|
||||||
|
"numberings": Object {
|
||||||
|
"abstractNums": Array [],
|
||||||
|
"numberings": Array [],
|
||||||
|
},
|
||||||
|
"rels": Object {
|
||||||
|
"rels": Array [
|
||||||
|
Array [
|
||||||
|
"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties",
|
||||||
|
"rId1",
|
||||||
|
"docProps/core.xml",
|
||||||
|
],
|
||||||
|
Array [
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties",
|
||||||
|
"rId2",
|
||||||
|
"docProps/app.xml",
|
||||||
|
],
|
||||||
|
Array [
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
|
||||||
|
"rId3",
|
||||||
|
"word/document.xml",
|
||||||
|
],
|
||||||
|
Array [
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties",
|
||||||
|
"rId4",
|
||||||
|
"docProps/custom.xml",
|
||||||
|
],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"settings": Object {
|
||||||
|
"defaultTabStop": 840,
|
||||||
|
"docId": null,
|
||||||
|
"docVars": Array [],
|
||||||
|
"zoom": 100,
|
||||||
|
},
|
||||||
|
"styles": Object {
|
||||||
|
"docDefaults": Object {
|
||||||
|
"runPropertyDefault": Object {
|
||||||
|
"runProperty": Object {
|
||||||
|
"bold": null,
|
||||||
|
"boldCs": null,
|
||||||
|
"color": null,
|
||||||
|
"del": null,
|
||||||
|
"fonts": null,
|
||||||
|
"highlight": null,
|
||||||
|
"ins": null,
|
||||||
|
"italic": null,
|
||||||
|
"italicCs": null,
|
||||||
|
"spacing": null,
|
||||||
|
"sz": null,
|
||||||
|
"szCs": null,
|
||||||
|
"textBorder": null,
|
||||||
|
"underline": null,
|
||||||
|
"vanish": null,
|
||||||
|
"vertAlign": null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"styles": Array [
|
||||||
|
Object {
|
||||||
|
"basedOn": "Normal",
|
||||||
|
"name": "Normal",
|
||||||
|
"paragraphProperty": Object {
|
||||||
|
"alignment": null,
|
||||||
|
"divId": null,
|
||||||
|
"indent": null,
|
||||||
|
"keepLines": false,
|
||||||
|
"keepNext": false,
|
||||||
|
"lineHeight": null,
|
||||||
|
"numberingProperty": null,
|
||||||
|
"pageBreakBefore": false,
|
||||||
|
"runProperty": Object {
|
||||||
|
"bold": null,
|
||||||
|
"boldCs": null,
|
||||||
|
"color": null,
|
||||||
|
"del": null,
|
||||||
|
"fonts": null,
|
||||||
|
"highlight": null,
|
||||||
|
"ins": null,
|
||||||
|
"italic": null,
|
||||||
|
"italicCs": null,
|
||||||
|
"spacing": null,
|
||||||
|
"sz": null,
|
||||||
|
"szCs": null,
|
||||||
|
"textBorder": null,
|
||||||
|
"underline": null,
|
||||||
|
"vanish": null,
|
||||||
|
"vertAlign": null,
|
||||||
|
},
|
||||||
|
"style": null,
|
||||||
|
"windowControl": false,
|
||||||
|
},
|
||||||
|
"runProperty": Object {
|
||||||
|
"bold": null,
|
||||||
|
"boldCs": null,
|
||||||
|
"color": null,
|
||||||
|
"del": null,
|
||||||
|
"fonts": null,
|
||||||
|
"highlight": null,
|
||||||
|
"ins": null,
|
||||||
|
"italic": null,
|
||||||
|
"italicCs": null,
|
||||||
|
"spacing": null,
|
||||||
|
"sz": null,
|
||||||
|
"szCs": null,
|
||||||
|
"textBorder": null,
|
||||||
|
"underline": null,
|
||||||
|
"vanish": null,
|
||||||
|
"vertAlign": null,
|
||||||
|
},
|
||||||
|
"styleId": "Normal",
|
||||||
|
"styleType": "paragraph",
|
||||||
|
"tableCellProperty": Object {
|
||||||
|
"borders": null,
|
||||||
|
"gridSpan": null,
|
||||||
|
"shading": null,
|
||||||
|
"textDirection": null,
|
||||||
|
"verticalAlign": null,
|
||||||
|
"verticalMerge": null,
|
||||||
|
"width": null,
|
||||||
|
},
|
||||||
|
"tableProperty": Object {
|
||||||
|
"borders": Object {
|
||||||
|
"bottom": Object {
|
||||||
|
"borderType": "single",
|
||||||
|
"color": "000000",
|
||||||
|
"position": "bottom",
|
||||||
|
"size": 2,
|
||||||
|
"space": 0,
|
||||||
|
},
|
||||||
|
"insideH": Object {
|
||||||
|
"borderType": "single",
|
||||||
|
"color": "000000",
|
||||||
|
"position": "insideH",
|
||||||
|
"size": 2,
|
||||||
|
"space": 0,
|
||||||
|
},
|
||||||
|
"insideV": Object {
|
||||||
|
"borderType": "single",
|
||||||
|
"color": "000000",
|
||||||
|
"position": "insideV",
|
||||||
|
"size": 2,
|
||||||
|
"space": 0,
|
||||||
|
},
|
||||||
|
"left": Object {
|
||||||
|
"borderType": "single",
|
||||||
|
"color": "000000",
|
||||||
|
"position": "left",
|
||||||
|
"size": 2,
|
||||||
|
"space": 0,
|
||||||
|
},
|
||||||
|
"right": Object {
|
||||||
|
"borderType": "single",
|
||||||
|
"color": "000000",
|
||||||
|
"position": "right",
|
||||||
|
"size": 2,
|
||||||
|
"space": 0,
|
||||||
|
},
|
||||||
|
"top": Object {
|
||||||
|
"borderType": "single",
|
||||||
|
"color": "000000",
|
||||||
|
"position": "top",
|
||||||
|
"size": 2,
|
||||||
|
"space": 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"indent": null,
|
||||||
|
"justification": "left",
|
||||||
|
"layout": null,
|
||||||
|
"margins": Object {
|
||||||
|
"bottom": Object {
|
||||||
|
"val": 0,
|
||||||
|
"widthType": "DXA",
|
||||||
|
},
|
||||||
|
"left": Object {
|
||||||
|
"val": 55,
|
||||||
|
"widthType": "DXA",
|
||||||
|
},
|
||||||
|
"right": Object {
|
||||||
|
"val": 55,
|
||||||
|
"widthType": "DXA",
|
||||||
|
},
|
||||||
|
"top": Object {
|
||||||
|
"val": 0,
|
||||||
|
"widthType": "DXA",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"style": null,
|
||||||
|
"width": Object {
|
||||||
|
"width": 0,
|
||||||
|
"widthType": "Auto",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"webSettings": Object {
|
||||||
|
"divs": Array [],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`reader should read div docx 1`] = `
|
||||||
|
Object {
|
||||||
|
"comments": Object {
|
||||||
|
"comments": Array [],
|
||||||
|
},
|
||||||
|
"commentsExtended": Object {
|
||||||
|
"children": Array [],
|
||||||
|
},
|
||||||
|
"contentType": Object {
|
||||||
|
"types": Object {
|
||||||
|
"/_rels/.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
||||||
|
"/docProps/app.xml": "application/vnd.openxmlformats-officedocument.extended-properties+xml",
|
||||||
|
"/docProps/core.xml": "application/vnd.openxmlformats-package.core-properties+xml",
|
||||||
|
"/docProps/custom.xml": "application/vnd.openxmlformats-officedocument.custom-properties+xml",
|
||||||
|
"/word/_rels/document.xml.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
||||||
|
"/word/comments.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",
|
||||||
|
"/word/commentsExtended.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",
|
||||||
|
"/word/document.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml",
|
||||||
|
"/word/fontTable.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml",
|
||||||
|
"/word/header1.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml",
|
||||||
|
"/word/numbering.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml",
|
||||||
|
"/word/settings.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml",
|
||||||
|
"/word/styles.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"docProps": Object {
|
||||||
|
"app": Object {},
|
||||||
|
"core": Object {
|
||||||
|
"config": Object {
|
||||||
|
"created": null,
|
||||||
|
"creator": null,
|
||||||
|
"description": null,
|
||||||
|
"language": null,
|
||||||
|
"lastModifiedBy": null,
|
||||||
|
"modified": null,
|
||||||
|
"revision": null,
|
||||||
|
"subject": null,
|
||||||
|
"title": null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"custom": Object {
|
||||||
|
"properties": Object {},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"document": Object {
|
"document": Object {
|
||||||
"children": Array [
|
"children": Array [
|
||||||
|
@ -459,6 +823,11 @@ Object {
|
||||||
"rId3",
|
"rId3",
|
||||||
"word/document.xml",
|
"word/document.xml",
|
||||||
],
|
],
|
||||||
|
Array [
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties",
|
||||||
|
"rId4",
|
||||||
|
"docProps/custom.xml",
|
||||||
|
],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
"settings": Object {
|
"settings": Object {
|
||||||
|
@ -1316,6 +1685,7 @@ Object {
|
||||||
"/_rels/.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
"/_rels/.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
||||||
"/docProps/app.xml": "application/vnd.openxmlformats-officedocument.extended-properties+xml",
|
"/docProps/app.xml": "application/vnd.openxmlformats-officedocument.extended-properties+xml",
|
||||||
"/docProps/core.xml": "application/vnd.openxmlformats-package.core-properties+xml",
|
"/docProps/core.xml": "application/vnd.openxmlformats-package.core-properties+xml",
|
||||||
|
"/docProps/custom.xml": "application/vnd.openxmlformats-officedocument.custom-properties+xml",
|
||||||
"/word/_rels/document.xml.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
"/word/_rels/document.xml.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
||||||
"/word/comments.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",
|
"/word/comments.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",
|
||||||
"/word/commentsExtended.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",
|
"/word/commentsExtended.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",
|
||||||
|
@ -1342,6 +1712,9 @@ Object {
|
||||||
"title": null,
|
"title": null,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"custom": Object {
|
||||||
|
"properties": Object {},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"document": Object {
|
"document": Object {
|
||||||
"children": Array [
|
"children": Array [
|
||||||
|
@ -1896,6 +2269,11 @@ Object {
|
||||||
"rId3",
|
"rId3",
|
||||||
"word/document.xml",
|
"word/document.xml",
|
||||||
],
|
],
|
||||||
|
Array [
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties",
|
||||||
|
"rId4",
|
||||||
|
"docProps/custom.xml",
|
||||||
|
],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
"settings": Object {
|
"settings": Object {
|
||||||
|
@ -2084,6 +2462,7 @@ Object {
|
||||||
"/_rels/.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
"/_rels/.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
||||||
"/docProps/app.xml": "application/vnd.openxmlformats-officedocument.extended-properties+xml",
|
"/docProps/app.xml": "application/vnd.openxmlformats-officedocument.extended-properties+xml",
|
||||||
"/docProps/core.xml": "application/vnd.openxmlformats-package.core-properties+xml",
|
"/docProps/core.xml": "application/vnd.openxmlformats-package.core-properties+xml",
|
||||||
|
"/docProps/custom.xml": "application/vnd.openxmlformats-officedocument.custom-properties+xml",
|
||||||
"/word/_rels/document.xml.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
"/word/_rels/document.xml.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
||||||
"/word/comments.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",
|
"/word/comments.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",
|
||||||
"/word/commentsExtended.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",
|
"/word/commentsExtended.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",
|
||||||
|
@ -2110,6 +2489,9 @@ Object {
|
||||||
"title": null,
|
"title": null,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"custom": Object {
|
||||||
|
"properties": Object {},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"document": Object {
|
"document": Object {
|
||||||
"children": Array [
|
"children": Array [
|
||||||
|
@ -4370,6 +4752,11 @@ Object {
|
||||||
"rId3",
|
"rId3",
|
||||||
"word/document.xml",
|
"word/document.xml",
|
||||||
],
|
],
|
||||||
|
Array [
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties",
|
||||||
|
"rId4",
|
||||||
|
"docProps/custom.xml",
|
||||||
|
],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
"settings": Object {
|
"settings": Object {
|
||||||
|
@ -4927,6 +5314,7 @@ Object {
|
||||||
"/_rels/.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
"/_rels/.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
||||||
"/docProps/app.xml": "application/vnd.openxmlformats-officedocument.extended-properties+xml",
|
"/docProps/app.xml": "application/vnd.openxmlformats-officedocument.extended-properties+xml",
|
||||||
"/docProps/core.xml": "application/vnd.openxmlformats-package.core-properties+xml",
|
"/docProps/core.xml": "application/vnd.openxmlformats-package.core-properties+xml",
|
||||||
|
"/docProps/custom.xml": "application/vnd.openxmlformats-officedocument.custom-properties+xml",
|
||||||
"/word/_rels/document.xml.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
"/word/_rels/document.xml.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
||||||
"/word/comments.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",
|
"/word/comments.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",
|
||||||
"/word/commentsExtended.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",
|
"/word/commentsExtended.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",
|
||||||
|
@ -4953,6 +5341,9 @@ Object {
|
||||||
"title": null,
|
"title": null,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"custom": Object {
|
||||||
|
"properties": Object {},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"document": Object {
|
"document": Object {
|
||||||
"children": Array [
|
"children": Array [
|
||||||
|
@ -7337,6 +7728,11 @@ Object {
|
||||||
"rId3",
|
"rId3",
|
||||||
"word/document.xml",
|
"word/document.xml",
|
||||||
],
|
],
|
||||||
|
Array [
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties",
|
||||||
|
"rId4",
|
||||||
|
"docProps/custom.xml",
|
||||||
|
],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
"settings": Object {
|
"settings": Object {
|
||||||
|
@ -8645,6 +9041,7 @@ Object {
|
||||||
"/_rels/.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
"/_rels/.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
||||||
"/docProps/app.xml": "application/vnd.openxmlformats-officedocument.extended-properties+xml",
|
"/docProps/app.xml": "application/vnd.openxmlformats-officedocument.extended-properties+xml",
|
||||||
"/docProps/core.xml": "application/vnd.openxmlformats-package.core-properties+xml",
|
"/docProps/core.xml": "application/vnd.openxmlformats-package.core-properties+xml",
|
||||||
|
"/docProps/custom.xml": "application/vnd.openxmlformats-officedocument.custom-properties+xml",
|
||||||
"/word/_rels/document.xml.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
"/word/_rels/document.xml.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
||||||
"/word/comments.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",
|
"/word/comments.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",
|
||||||
"/word/commentsExtended.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",
|
"/word/commentsExtended.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",
|
||||||
|
@ -8671,6 +9068,9 @@ Object {
|
||||||
"title": null,
|
"title": null,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"custom": Object {
|
||||||
|
"properties": Object {},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"document": Object {
|
"document": Object {
|
||||||
"children": Array [
|
"children": Array [
|
||||||
|
@ -11076,6 +11476,11 @@ Object {
|
||||||
"rId3",
|
"rId3",
|
||||||
"word/document.xml",
|
"word/document.xml",
|
||||||
],
|
],
|
||||||
|
Array [
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties",
|
||||||
|
"rId4",
|
||||||
|
"docProps/custom.xml",
|
||||||
|
],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
"settings": Object {
|
"settings": Object {
|
||||||
|
@ -12587,6 +12992,7 @@ Object {
|
||||||
"/_rels/.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
"/_rels/.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
||||||
"/docProps/app.xml": "application/vnd.openxmlformats-officedocument.extended-properties+xml",
|
"/docProps/app.xml": "application/vnd.openxmlformats-officedocument.extended-properties+xml",
|
||||||
"/docProps/core.xml": "application/vnd.openxmlformats-package.core-properties+xml",
|
"/docProps/core.xml": "application/vnd.openxmlformats-package.core-properties+xml",
|
||||||
|
"/docProps/custom.xml": "application/vnd.openxmlformats-officedocument.custom-properties+xml",
|
||||||
"/word/_rels/document.xml.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
"/word/_rels/document.xml.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
||||||
"/word/comments.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",
|
"/word/comments.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",
|
||||||
"/word/commentsExtended.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",
|
"/word/commentsExtended.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",
|
||||||
|
@ -12613,6 +13019,9 @@ Object {
|
||||||
"title": null,
|
"title": null,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"custom": Object {
|
||||||
|
"properties": Object {},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"document": Object {
|
"document": Object {
|
||||||
"children": Array [
|
"children": Array [
|
||||||
|
@ -13464,6 +13873,11 @@ Object {
|
||||||
"rId3",
|
"rId3",
|
||||||
"word/document.xml",
|
"word/document.xml",
|
||||||
],
|
],
|
||||||
|
Array [
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties",
|
||||||
|
"rId4",
|
||||||
|
"docProps/custom.xml",
|
||||||
|
],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
"settings": Object {
|
"settings": Object {
|
||||||
|
@ -14174,6 +14588,7 @@ Object {
|
||||||
"/_rels/.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
"/_rels/.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
||||||
"/docProps/app.xml": "application/vnd.openxmlformats-officedocument.extended-properties+xml",
|
"/docProps/app.xml": "application/vnd.openxmlformats-officedocument.extended-properties+xml",
|
||||||
"/docProps/core.xml": "application/vnd.openxmlformats-package.core-properties+xml",
|
"/docProps/core.xml": "application/vnd.openxmlformats-package.core-properties+xml",
|
||||||
|
"/docProps/custom.xml": "application/vnd.openxmlformats-officedocument.custom-properties+xml",
|
||||||
"/word/_rels/document.xml.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
"/word/_rels/document.xml.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
||||||
"/word/comments.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",
|
"/word/comments.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",
|
||||||
"/word/commentsExtended.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",
|
"/word/commentsExtended.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",
|
||||||
|
@ -14200,6 +14615,9 @@ Object {
|
||||||
"title": null,
|
"title": null,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"custom": Object {
|
||||||
|
"properties": Object {},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"document": Object {
|
"document": Object {
|
||||||
"children": Array [
|
"children": Array [
|
||||||
|
@ -14718,6 +15136,11 @@ Object {
|
||||||
"rId3",
|
"rId3",
|
||||||
"word/document.xml",
|
"word/document.xml",
|
||||||
],
|
],
|
||||||
|
Array [
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties",
|
||||||
|
"rId4",
|
||||||
|
"docProps/custom.xml",
|
||||||
|
],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
"settings": Object {
|
"settings": Object {
|
||||||
|
@ -15410,6 +15833,7 @@ Object {
|
||||||
"/_rels/.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
"/_rels/.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
||||||
"/docProps/app.xml": "application/vnd.openxmlformats-officedocument.extended-properties+xml",
|
"/docProps/app.xml": "application/vnd.openxmlformats-officedocument.extended-properties+xml",
|
||||||
"/docProps/core.xml": "application/vnd.openxmlformats-package.core-properties+xml",
|
"/docProps/core.xml": "application/vnd.openxmlformats-package.core-properties+xml",
|
||||||
|
"/docProps/custom.xml": "application/vnd.openxmlformats-officedocument.custom-properties+xml",
|
||||||
"/word/_rels/document.xml.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
"/word/_rels/document.xml.rels": "application/vnd.openxmlformats-package.relationships+xml",
|
||||||
"/word/comments.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",
|
"/word/comments.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",
|
||||||
"/word/commentsExtended.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",
|
"/word/commentsExtended.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",
|
||||||
|
@ -15436,6 +15860,9 @@ Object {
|
||||||
"title": null,
|
"title": null,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"custom": Object {
|
||||||
|
"properties": Object {},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"document": Object {
|
"document": Object {
|
||||||
"children": Array [
|
"children": Array [
|
||||||
|
@ -15755,6 +16182,11 @@ Object {
|
||||||
"rId3",
|
"rId3",
|
||||||
"word/document.xml",
|
"word/document.xml",
|
||||||
],
|
],
|
||||||
|
Array [
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties",
|
||||||
|
"rId4",
|
||||||
|
"docProps/custom.xml",
|
||||||
|
],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
"settings": Object {
|
"settings": Object {
|
||||||
|
@ -16329,6 +16761,40 @@ exports[`writer should write cell shading 3`] = `
|
||||||
</w:num></w:numbering>"
|
</w:num></w:numbering>"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`writer should write custom props 1`] = `
|
||||||
|
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\" standalone=\\"yes\\"?>
|
||||||
|
<Properties xmlns=\\"http://schemas.openxmlformats.org/officeDocument/2006/custom-properties\\" xmlns:vt=\\"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes\\">
|
||||||
|
<property fmtid=\\"{D5CDD505-2E9C-101B-9397-08002B2CF9AE}\\" pid=\\"2\\" name=\\"hello\\">
|
||||||
|
<vt:lpwstr>{\\"world\\": 0}</vt:lpwstr>
|
||||||
|
</property>
|
||||||
|
</Properties>"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`writer should write custom props 2`] = `
|
||||||
|
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
|
||||||
|
<Relationships xmlns=\\"http://schemas.openxmlformats.org/package/2006/relationships\\">
|
||||||
|
<Relationship Id=\\"rId1\\" Type=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles\\" Target=\\"styles.xml\\" />
|
||||||
|
<Relationship Id=\\"rId2\\" Type=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable\\" Target=\\"fontTable.xml\\" />
|
||||||
|
<Relationship Id=\\"rId3\\" Type=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings\\" Target=\\"settings.xml\\" />
|
||||||
|
<Relationship Id=\\"rId4\\" Type=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/header\\" Target=\\"header1.xml\\" />
|
||||||
|
<Relationship Id=\\"rId5\\" Type=\\"http://schemas.microsoft.com/office/2011/relationships/commentsExtended\\" Target=\\"commentsExtended.xml\\" />
|
||||||
|
</Relationships>"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`writer should write custom props 3`] = `
|
||||||
|
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\" standalone=\\"yes\\"?>
|
||||||
|
<w:document 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\\" xmlns:w15=\\"http://schemas.microsoft.com/office/word/2012/wordml\\" mc:Ignorable=\\"w14 wp14\\">
|
||||||
|
<w:body><w:p w14:paraId=\\"00000001\\"><w:pPr><w:rPr /></w:pPr><w:r><w:rPr><w:rFonts /></w:rPr><w:t xml:space=\\"preserve\\">Hello!!</w:t></w:r></w:p><w:sectPr><w:pgSz w:w=\\"11906\\" w:h=\\"16838\\" /><w:pgMar w:top=\\"1985\\" w:right=\\"1701\\" w:bottom=\\"1701\\" w:left=\\"1701\\" w:header=\\"851\\" w:footer=\\"992\\" w:gutter=\\"0\\" /><w:headerReference w:type=\\"default\\" r:id=\\"rId4\\" /><w:cols w:space=\\"425\\" /><w:docGrid w:type=\\"lines\\" w:linePitch=\\"360\\" /></w:sectPr></w:body>
|
||||||
|
</w:document>"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`writer should write custom props 4`] = `
|
||||||
|
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\" standalone=\\"yes\\"?>
|
||||||
|
<w:numbering xmlns:r=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\\" xmlns:o=\\"urn:schemas-microsoft-com:office:office\\" xmlns:v=\\"urn:schemas-microsoft-com:vml\\" xmlns:w=\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\"><w:abstractNum w:abstractNumId=\\"1\\"><w:lvl w:ilvl=\\"0\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"%1.\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"420\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl><w:lvl w:ilvl=\\"1\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"(%2)\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"840\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl><w:lvl w:ilvl=\\"2\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimalEnclosedCircle\\" /><w:lvlText w:val=\\"%3\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"1260\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl><w:lvl w:ilvl=\\"3\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"%4.\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"1680\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl><w:lvl w:ilvl=\\"4\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"(%5)\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"2100\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl><w:lvl w:ilvl=\\"5\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimalEnclosedCircle\\" /><w:lvlText w:val=\\"%6\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"2520\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl><w:lvl w:ilvl=\\"6\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"%7.\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"2940\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl><w:lvl w:ilvl=\\"7\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"(%8)\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"3360\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl><w:lvl w:ilvl=\\"8\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimalEnclosedCircle\\" /><w:lvlText w:val=\\"%9\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"3780\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl></w:abstractNum><w:num w:numId=\\"1\\">
|
||||||
|
<w:abstractNumId w:val=\\"1\\" />
|
||||||
|
</w:num></w:numbering>"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`writer should write default font 1`] = `
|
exports[`writer should write default font 1`] = `
|
||||||
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
|
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
|
||||||
<Relationships xmlns=\\"http://schemas.openxmlformats.org/package/2006/relationships\\">
|
<Relationships xmlns=\\"http://schemas.openxmlformats.org/package/2006/relationships\\">
|
||||||
|
|
|
@ -22,6 +22,13 @@ describe("reader", () => {
|
||||||
expect(json).toMatchSnapshot();
|
expect(json).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("should read custom docx", () => {
|
||||||
|
const buffer = readFileSync("../fixtures/custom/custom.docx");
|
||||||
|
const json = w.readDocx(buffer);
|
||||||
|
writeFileSync("../output/custom.json", JSON.stringify(json, null, 2));
|
||||||
|
expect(json).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
test("should read table style docx", () => {
|
test("should read table style docx", () => {
|
||||||
const buffer = readFileSync("../fixtures/table_style/table_style.docx");
|
const buffer = readFileSync("../fixtures/table_style/table_style.docx");
|
||||||
const json = w.readDocx(buffer);
|
const json = w.readDocx(buffer);
|
||||||
|
@ -272,4 +279,19 @@ describe("writer", () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("should write custom props", () => {
|
||||||
|
const p = new w.Paragraph().addRun(new w.Run().addText("Hello!!"));
|
||||||
|
const buffer = new w.Docx()
|
||||||
|
.addParagraph(p)
|
||||||
|
.customProperty('hello', '{"world": 0}')
|
||||||
|
.build();
|
||||||
|
writeFileSync("../output/custom.docx", buffer);
|
||||||
|
const z = new Zip(Buffer.from(buffer));
|
||||||
|
for (const e of z.getEntries()) {
|
||||||
|
if (e.entryName.match(/document.xml|numbering.xml|custom.xml/)) {
|
||||||
|
expect(z.readAsText(e)).toMatchSnapshot();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue