Support deleted toc (#595)
* fix: add delete in table of contents * feat: support deleted toc * fixmain
parent
34ebfc5290
commit
838052be0f
|
@ -4,7 +4,7 @@ pub fn main() -> Result<(), DocxError> {
|
||||||
let path = std::path::Path::new("./output/toc_simple.docx");
|
let path = std::path::Path::new("./output/toc_simple.docx");
|
||||||
let file = std::fs::File::create(&path).unwrap();
|
let file = std::fs::File::create(&path).unwrap();
|
||||||
let p1 = Paragraph::new()
|
let p1 = Paragraph::new()
|
||||||
.add_run(Run::new().add_text("Hello"))
|
.add_run(Run::new().add_text("!!Hello"))
|
||||||
.style("Heading1")
|
.style("Heading1")
|
||||||
.page_break_before(true);
|
.page_break_before(true);
|
||||||
let style1 = Style::new("Heading1", StyleType::Paragraph).name("Heading 1");
|
let style1 = Style::new("Heading1", StyleType::Paragraph).name("Heading 1");
|
||||||
|
|
|
@ -0,0 +1,92 @@
|
||||||
|
use serde::ser::{SerializeStruct, Serializer};
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use crate::documents::*;
|
||||||
|
use crate::xml_builder::*;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub enum DeleteInstrText {
|
||||||
|
TOC(InstrToC),
|
||||||
|
TC(InstrTC),
|
||||||
|
PAGEREF(InstrPAGEREF),
|
||||||
|
HYPERLINK(InstrHyperlink),
|
||||||
|
Unsupported(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BuildXML for Box<DeleteInstrText> {
|
||||||
|
fn build(&self) -> Vec<u8> {
|
||||||
|
let instr = match self.as_ref() {
|
||||||
|
DeleteInstrText::TOC(toc) => toc.build(),
|
||||||
|
DeleteInstrText::TC(tc) => tc.build(),
|
||||||
|
DeleteInstrText::PAGEREF(page_ref) => page_ref.build(),
|
||||||
|
DeleteInstrText::HYPERLINK(_link) => todo!(),
|
||||||
|
DeleteInstrText::Unsupported(s) => s.as_bytes().to_vec(),
|
||||||
|
};
|
||||||
|
XMLBuilder::new()
|
||||||
|
.open_delete_instr_text()
|
||||||
|
.add_bytes(&instr)
|
||||||
|
.close()
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Serialize for DeleteInstrText {
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
match *self {
|
||||||
|
DeleteInstrText::TOC(ref s) => {
|
||||||
|
let mut t = serializer.serialize_struct("TOC", 2)?;
|
||||||
|
t.serialize_field("type", "toc")?;
|
||||||
|
t.serialize_field("data", s)?;
|
||||||
|
t.end()
|
||||||
|
}
|
||||||
|
DeleteInstrText::TC(ref s) => {
|
||||||
|
let mut t = serializer.serialize_struct("TC", 2)?;
|
||||||
|
t.serialize_field("type", "tc")?;
|
||||||
|
t.serialize_field("data", s)?;
|
||||||
|
t.end()
|
||||||
|
}
|
||||||
|
DeleteInstrText::PAGEREF(ref s) => {
|
||||||
|
let mut t = serializer.serialize_struct("PAGEREF", 2)?;
|
||||||
|
t.serialize_field("type", "pageref")?;
|
||||||
|
t.serialize_field("data", s)?;
|
||||||
|
t.end()
|
||||||
|
}
|
||||||
|
DeleteInstrText::HYPERLINK(ref s) => {
|
||||||
|
let mut t = serializer.serialize_struct("HYPERLINK", 2)?;
|
||||||
|
t.serialize_field("type", "hyperlink")?;
|
||||||
|
t.serialize_field("data", s)?;
|
||||||
|
t.end()
|
||||||
|
}
|
||||||
|
DeleteInstrText::Unsupported(ref s) => {
|
||||||
|
let mut t = serializer.serialize_struct("Unsupported", 2)?;
|
||||||
|
t.serialize_field("type", "unsupported")?;
|
||||||
|
t.serialize_field("data", s)?;
|
||||||
|
t.end()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
#[cfg(test)]
|
||||||
|
use pretty_assertions::assert_eq;
|
||||||
|
use std::str;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_delete_toc_instr() {
|
||||||
|
let b = Box::new(DeleteInstrText::TOC(
|
||||||
|
InstrToC::new().heading_styles_range(1, 3),
|
||||||
|
))
|
||||||
|
.build();
|
||||||
|
assert_eq!(
|
||||||
|
str::from_utf8(&b).unwrap(),
|
||||||
|
r#"<w:delInstrText>TOC \o "1-3"</w:delInstrText>"#
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,6 +16,7 @@ mod comment_range_start;
|
||||||
mod data_binding;
|
mod data_binding;
|
||||||
mod default_tab_stop;
|
mod default_tab_stop;
|
||||||
mod delete;
|
mod delete;
|
||||||
|
mod delete_instr_text;
|
||||||
mod delete_text;
|
mod delete_text;
|
||||||
mod div;
|
mod div;
|
||||||
mod doc_defaults;
|
mod doc_defaults;
|
||||||
|
@ -133,6 +134,7 @@ pub use comment_range_start::*;
|
||||||
pub use data_binding::*;
|
pub use data_binding::*;
|
||||||
pub use default_tab_stop::*;
|
pub use default_tab_stop::*;
|
||||||
pub use delete::*;
|
pub use delete::*;
|
||||||
|
pub use delete_instr_text::*;
|
||||||
pub use delete_text::*;
|
pub use delete_text::*;
|
||||||
pub use div::*;
|
pub use div::*;
|
||||||
pub use doc_defaults::*;
|
pub use doc_defaults::*;
|
||||||
|
|
|
@ -35,6 +35,7 @@ pub enum RunChild {
|
||||||
CommentEnd(CommentRangeEnd),
|
CommentEnd(CommentRangeEnd),
|
||||||
FieldChar(FieldChar),
|
FieldChar(FieldChar),
|
||||||
InstrText(Box<InstrText>),
|
InstrText(Box<InstrText>),
|
||||||
|
DeleteInstrText(Box<DeleteInstrText>),
|
||||||
// For reader
|
// For reader
|
||||||
InstrTextString(String),
|
InstrTextString(String),
|
||||||
}
|
}
|
||||||
|
@ -104,6 +105,12 @@ impl Serialize for RunChild {
|
||||||
t.serialize_field("data", i)?;
|
t.serialize_field("data", i)?;
|
||||||
t.end()
|
t.end()
|
||||||
}
|
}
|
||||||
|
RunChild::DeleteInstrText(ref i) => {
|
||||||
|
let mut t = serializer.serialize_struct("DeleteInstrText", 2)?;
|
||||||
|
t.serialize_field("type", "deleteInstrText")?;
|
||||||
|
t.serialize_field("data", i)?;
|
||||||
|
t.end()
|
||||||
|
}
|
||||||
RunChild::InstrTextString(ref i) => {
|
RunChild::InstrTextString(ref i) => {
|
||||||
let mut t = serializer.serialize_struct("InstrTextString", 2)?;
|
let mut t = serializer.serialize_struct("InstrTextString", 2)?;
|
||||||
t.serialize_field("type", "instrTextString")?;
|
t.serialize_field("type", "instrTextString")?;
|
||||||
|
@ -163,6 +170,11 @@ impl Run {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_delete_instr_text(mut self, i: DeleteInstrText) -> Run {
|
||||||
|
self.children.push(RunChild::DeleteInstrText(Box::new(i)));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn add_tab(mut self) -> Run {
|
pub fn add_tab(mut self) -> Run {
|
||||||
self.children.push(RunChild::Tab(Tab::new()));
|
self.children.push(RunChild::Tab(Tab::new()));
|
||||||
self
|
self
|
||||||
|
@ -279,7 +291,8 @@ impl BuildXML for Run {
|
||||||
RunChild::CommentEnd(c) => b = b.add_child(c),
|
RunChild::CommentEnd(c) => b = b.add_child(c),
|
||||||
RunChild::FieldChar(c) => b = b.add_child(c),
|
RunChild::FieldChar(c) => b = b.add_child(c),
|
||||||
RunChild::InstrText(c) => b = b.add_child(c),
|
RunChild::InstrText(c) => b = b.add_child(c),
|
||||||
_ => {}
|
RunChild::DeleteInstrText(c) => b = b.add_child(c),
|
||||||
|
RunChild::InstrTextString(_) => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b.close().build()
|
b.close().build()
|
||||||
|
|
|
@ -33,12 +33,19 @@ impl Serialize for TocContent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Debug, Clone, PartialEq, Default)]
|
||||||
|
pub struct TableOfContentsReviewData {
|
||||||
|
pub author: String,
|
||||||
|
pub date: String,
|
||||||
|
}
|
||||||
|
|
||||||
// https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_TOCTOC_topic_ID0ELZO1.html
|
// https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_TOCTOC_topic_ID0ELZO1.html
|
||||||
// This struct is only used by writers
|
// This struct is only used by writers
|
||||||
#[derive(Serialize, Debug, Clone, PartialEq, Default)]
|
#[derive(Serialize, Debug, Clone, PartialEq, Default)]
|
||||||
pub struct TableOfContents {
|
pub struct TableOfContents {
|
||||||
pub instr: InstrToC,
|
pub instr: InstrToC,
|
||||||
pub items: Vec<TableOfContentsItem>,
|
pub items: Vec<TableOfContentsItem>,
|
||||||
|
// don't use
|
||||||
pub auto: bool,
|
pub auto: bool,
|
||||||
pub dirty: bool,
|
pub dirty: bool,
|
||||||
pub alias: Option<String>,
|
pub alias: Option<String>,
|
||||||
|
@ -49,6 +56,8 @@ pub struct TableOfContents {
|
||||||
// it is inserted in after toc.
|
// it is inserted in after toc.
|
||||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||||
pub after_contents: Vec<TocContent>,
|
pub after_contents: Vec<TocContent>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub delete: Option<TableOfContentsReviewData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TableOfContents {
|
impl TableOfContents {
|
||||||
|
@ -84,6 +93,14 @@ impl TableOfContents {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn delete(mut self, author: impl Into<String>, date: impl Into<String>) -> Self {
|
||||||
|
self.delete = Some(TableOfContentsReviewData {
|
||||||
|
author: author.into(),
|
||||||
|
date: date.into(),
|
||||||
|
});
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
// pub fn tc_field_level_range(mut self, start: usize, end: usize) -> Self {
|
// pub fn tc_field_level_range(mut self, start: usize, end: usize) -> Self {
|
||||||
// self.instr = self.instr.tc_field_level_range(start, end);
|
// self.instr = self.instr.tc_field_level_range(start, end);
|
||||||
// self
|
// self
|
||||||
|
@ -133,13 +150,6 @@ impl BuildXML for TableOfContents {
|
||||||
p = p.alias(alias);
|
p = p.alias(alias);
|
||||||
}
|
}
|
||||||
if self.items.is_empty() {
|
if self.items.is_empty() {
|
||||||
let p1 = Paragraph::new().add_run(
|
|
||||||
Run::new()
|
|
||||||
.add_field_char(FieldCharType::Begin, true)
|
|
||||||
.add_instr_text(InstrText::TOC(self.instr.clone()))
|
|
||||||
.add_field_char(FieldCharType::Separate, false),
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut b = XMLBuilder::new()
|
let mut b = XMLBuilder::new()
|
||||||
.open_structured_tag()
|
.open_structured_tag()
|
||||||
.add_child(&p)
|
.add_child(&p)
|
||||||
|
@ -156,6 +166,23 @@ impl BuildXML for TableOfContents {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let p1 = if let Some(ref del) = self.delete {
|
||||||
|
Paragraph::new().add_delete(
|
||||||
|
Delete::new().author(&del.author).date(&del.date).add_run(
|
||||||
|
Run::new()
|
||||||
|
.add_field_char(FieldCharType::Begin, true)
|
||||||
|
.add_delete_instr_text(DeleteInstrText::TOC(self.instr.clone()))
|
||||||
|
.add_field_char(FieldCharType::Separate, false),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Paragraph::new().add_run(
|
||||||
|
Run::new()
|
||||||
|
.add_field_char(FieldCharType::Begin, true)
|
||||||
|
.add_instr_text(InstrText::TOC(self.instr.clone()))
|
||||||
|
.add_field_char(FieldCharType::Separate, false),
|
||||||
|
)
|
||||||
|
};
|
||||||
b = b.add_child(&p1);
|
b = b.add_child(&p1);
|
||||||
|
|
||||||
let p2 = Paragraph::new().add_run(Run::new().add_field_char(FieldCharType::End, false));
|
let p2 = Paragraph::new().add_run(Run::new().add_field_char(FieldCharType::End, false));
|
||||||
|
|
|
@ -159,6 +159,7 @@ impl XMLBuilder {
|
||||||
closed!(field_character, "w:fldChar", "w:fldCharType", "w:dirty");
|
closed!(field_character, "w:fldChar", "w:fldCharType", "w:dirty");
|
||||||
|
|
||||||
open!(open_instr_text, "w:instrText");
|
open!(open_instr_text, "w:instrText");
|
||||||
|
open!(open_delete_instr_text, "w:delInstrText");
|
||||||
|
|
||||||
closed!(text_direction, "w:textDirection", "w:val");
|
closed!(text_direction, "w:textDirection", "w:val");
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ export class TableOfContents {
|
||||||
_pageRefPlaceholder = "";
|
_pageRefPlaceholder = "";
|
||||||
_beforeContents: (Paragraph | Table)[] = [];
|
_beforeContents: (Paragraph | Table)[] = [];
|
||||||
_afterContents: (Paragraph | Table)[] = [];
|
_afterContents: (Paragraph | Table)[] = [];
|
||||||
|
_delete: { author: string; date: string } | null = null;
|
||||||
|
|
||||||
constructor(instrText?: string) {
|
constructor(instrText?: string) {
|
||||||
this._instrText = instrText;
|
this._instrText = instrText;
|
||||||
|
@ -76,6 +77,11 @@ export class TableOfContents {
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
delete = (author: string, date: string) => {
|
||||||
|
this._delete = { author, date };
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
addItem = (item: TableOfContentsItem) => {
|
addItem = (item: TableOfContentsItem) => {
|
||||||
this._items.push(item);
|
this._items.push(item);
|
||||||
return this;
|
return this;
|
||||||
|
@ -112,6 +118,10 @@ export class TableOfContents {
|
||||||
toc = toc.page_ref_placeholder(this._pageRefPlaceholder);
|
toc = toc.page_ref_placeholder(this._pageRefPlaceholder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this._delete) {
|
||||||
|
toc = toc.delete(this._delete.author, this._delete.date);
|
||||||
|
}
|
||||||
|
|
||||||
for (const sl of this._styleWithLevels) {
|
for (const sl of this._styleWithLevels) {
|
||||||
toc = toc.add_style_with_level(sl.styleId, sl.level);
|
toc = toc.add_style_with_level(sl.styleId, sl.level);
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,11 @@ impl TableOfContents {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn delete(mut self, author: &str, date: &str) -> Self {
|
||||||
|
self.0 = self.0.delete(author, date);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn add_before_paragraph(mut self, p: Paragraph) -> Self {
|
pub fn add_before_paragraph(mut self, p: Paragraph) -> Self {
|
||||||
self.0 = self.0.add_before_paragraph(p.take());
|
self.0 = self.0.add_before_paragraph(p.take());
|
||||||
self
|
self
|
||||||
|
|
|
@ -152157,6 +152157,27 @@ exports[`writer should write default font 3`] = `
|
||||||
</w:num></w:numbering>"
|
</w:num></w:numbering>"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`writer should write deleted ToC 1`] = `
|
||||||
|
"<?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=\\"rId5\\" Type=\\"http://schemas.microsoft.com/office/2011/relationships/commentsExtended\\" Target=\\"commentsExtended.xml\\" />
|
||||||
|
</Relationships>"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`writer should write deleted ToC 2`] = `
|
||||||
|
"<?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:sdt><w:sdtPr><w:rPr /><w:alias w:val=\\"Table of contents\\" />
|
||||||
|
</w:sdtPr><w:sdtContent><w:p w14:paraId=\\"00000001\\"><w:pPr><w:rPr /></w:pPr><w:del w:id=\\"0\\" w:author=\\"bokuweb\\" w:date=\\"2021-12-23T18:16:00Z\\"><w:r><w:rPr /><w:fldChar w:fldCharType=\\"begin\\" w:dirty=\\"true\\" /><w:delInstrText>TOC \\\\u</w:delInstrText><w:fldChar w:fldCharType=\\"separate\\" w:dirty=\\"false\\" /></w:r></w:del></w:p><w:p w14:paraId=\\"00000003\\"><w:pPr><w:rPr /></w:pPr><w:r><w:rPr /><w:fldChar w:fldCharType=\\"end\\" w:dirty=\\"false\\" /></w:r><w:r><w:rPr /><w:t xml:space=\\"preserve\\">After contents</w:t></w:r></w:p></w:sdtContent>
|
||||||
|
</w:sdt><w:p w14:paraId=\\"00000004\\"><w:pPr><w:rPr /><w:pStyle w:val=\\"Heading1\\" /><w:pageBreakBefore />
|
||||||
|
</w:pPr><w:r><w:rPr /><w:t xml:space=\\"preserve\\">Hello!!</w:t></w:r></w:p><w:p w14:paraId=\\"00000005\\"><w:pPr><w:rPr /><w:pStyle w:val=\\"Heading2\\" /><w:pageBreakBefore />
|
||||||
|
</w:pPr><w:r><w:rPr /><w:t xml:space=\\"preserve\\">World</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:cols w:space=\\"425\\" w:num=\\"1\\" /><w:docGrid w:type=\\"lines\\" w:linePitch=\\"360\\" /></w:sectPr></w:body>
|
||||||
|
</w:document>"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`writer should write dirty and disable auto items ToC 1`] = `
|
exports[`writer should write dirty and disable auto items ToC 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\\">
|
||||||
|
@ -152486,7 +152507,7 @@ exports[`writer should write jpeg image with del 1`] = `
|
||||||
exports[`writer should write jpeg image with del 2`] = `
|
exports[`writer should write jpeg image with del 2`] = `
|
||||||
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\" standalone=\\"yes\\"?>
|
"<?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: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:del w:id=\\"2\\" w:author=\\"bokuweb\\" w:date=\\"2021-12-23T18:16:00Z\\"><w:r><w:rPr /><w:drawing>
|
<w:body><w:p w14:paraId=\\"00000001\\"><w:pPr><w:rPr /></w:pPr><w:del w:id=\\"3\\" w:author=\\"bokuweb\\" w:date=\\"2021-12-23T18:16:00Z\\"><w:r><w:rPr /><w:drawing>
|
||||||
<wp:inline distT=\\"0\\" distB=\\"0\\" distL=\\"0\\" distR=\\"0\\">
|
<wp:inline distT=\\"0\\" distB=\\"0\\" distL=\\"0\\" distR=\\"0\\">
|
||||||
<wp:extent cx=\\"3048000\\" cy=\\"2286000\\" />
|
<wp:extent cx=\\"3048000\\" cy=\\"2286000\\" />
|
||||||
<wp:effectExtent b=\\"0\\" l=\\"0\\" r=\\"0\\" t=\\"0\\" />
|
<wp:effectExtent b=\\"0\\" l=\\"0\\" r=\\"0\\" t=\\"0\\" />
|
||||||
|
@ -152539,7 +152560,7 @@ exports[`writer should write jpeg image with ins 1`] = `
|
||||||
exports[`writer should write jpeg image with ins 2`] = `
|
exports[`writer should write jpeg image with ins 2`] = `
|
||||||
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\" standalone=\\"yes\\"?>
|
"<?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: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:ins w:id=\\"1\\" w:author=\\"bokuweb\\" w:date=\\"2021-12-23T18:16:00Z\\"><w:r><w:rPr /><w:drawing>
|
<w:body><w:p w14:paraId=\\"00000001\\"><w:pPr><w:rPr /></w:pPr><w:ins w:id=\\"2\\" w:author=\\"bokuweb\\" w:date=\\"2021-12-23T18:16:00Z\\"><w:r><w:rPr /><w:drawing>
|
||||||
<wp:inline distT=\\"0\\" distB=\\"0\\" distL=\\"0\\" distR=\\"0\\">
|
<wp:inline distT=\\"0\\" distB=\\"0\\" distL=\\"0\\" distR=\\"0\\">
|
||||||
<wp:extent cx=\\"3048000\\" cy=\\"2286000\\" />
|
<wp:extent cx=\\"3048000\\" cy=\\"2286000\\" />
|
||||||
<wp:effectExtent b=\\"0\\" l=\\"0\\" r=\\"0\\" t=\\"0\\" />
|
<wp:effectExtent b=\\"0\\" l=\\"0\\" r=\\"0\\" t=\\"0\\" />
|
||||||
|
@ -152801,7 +152822,7 @@ exports[`writer should write paragraph delete 1`] = `
|
||||||
exports[`writer should write paragraph delete 2`] = `
|
exports[`writer should write paragraph delete 2`] = `
|
||||||
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\" standalone=\\"yes\\"?>
|
"<?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: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=\\"00000003\\"><w:pPr><w:rPr><w:del w:id=\\"0\\" w:author=\\"bokuweb\\" w:date=\\"2021-12-23T18:16:00Z\\" /></w:rPr><w:numPr><w:numId w:val=\\"1\\" /><w:ilvl w:val=\\"0\\" /></w:numPr></w:pPr><w:r><w:rPr /><w:t xml:space=\\"preserve\\">Hello world!!</w:t></w:r></w:p><w:p w14:paraId=\\"00000004\\"><w:pPr><w:rPr /><w:numPr><w:numId w:val=\\"1\\" /><w:ilvl w:val=\\"0\\" /></w:numPr></w:pPr><w:r><w:rPr /><w:t xml:space=\\"preserve\\">Foo</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:cols w:space=\\"425\\" w:num=\\"1\\" /><w:docGrid w:type=\\"lines\\" w:linePitch=\\"360\\" /></w:sectPr></w:body>
|
<w:body><w:p w14:paraId=\\"00000003\\"><w:pPr><w:rPr><w:del w:id=\\"1\\" w:author=\\"bokuweb\\" w:date=\\"2021-12-23T18:16:00Z\\" /></w:rPr><w:numPr><w:numId w:val=\\"1\\" /><w:ilvl w:val=\\"0\\" /></w:numPr></w:pPr><w:r><w:rPr /><w:t xml:space=\\"preserve\\">Hello world!!</w:t></w:r></w:p><w:p w14:paraId=\\"00000004\\"><w:pPr><w:rPr /><w:numPr><w:numId w:val=\\"1\\" /><w:ilvl w:val=\\"0\\" /></w:numPr></w:pPr><w:r><w:rPr /><w:t xml:space=\\"preserve\\">Foo</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:cols w:space=\\"425\\" w:num=\\"1\\" /><w:docGrid w:type=\\"lines\\" w:linePitch=\\"360\\" /></w:sectPr></w:body>
|
||||||
</w:document>"
|
</w:document>"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
|
@ -795,6 +795,42 @@ describe("writer", () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("should write deleted ToC", () => {
|
||||||
|
const after = new w.Paragraph().addRun(
|
||||||
|
new w.Run().addText("After contents")
|
||||||
|
);
|
||||||
|
const p1 = new w.Paragraph()
|
||||||
|
.addRun(new w.Run().addText("Hello!!"))
|
||||||
|
.pageBreakBefore(true)
|
||||||
|
.style("Heading1");
|
||||||
|
const style1 = new w.Style("Heading1", "paragraph").name("Heading 1");
|
||||||
|
const p2 = new w.Paragraph()
|
||||||
|
.addRun(new w.Run().addText("World"))
|
||||||
|
.pageBreakBefore(true)
|
||||||
|
.style("Heading2");
|
||||||
|
const style2 = new w.Style("Heading2", "paragraph").name("Heading 2");
|
||||||
|
const buffer = new w.Docx()
|
||||||
|
.addTableOfContents(
|
||||||
|
new w.TableOfContents(`TOC \o "1-3" \h \z \\u`)
|
||||||
|
.alias("Table of contents")
|
||||||
|
.delete("bokuweb", "2021-12-23T18:16:00Z")
|
||||||
|
.addAfterParagraph(after)
|
||||||
|
.dirty()
|
||||||
|
)
|
||||||
|
.addParagraph(p1)
|
||||||
|
.addParagraph(p2)
|
||||||
|
.addStyle(style1)
|
||||||
|
.addStyle(style2)
|
||||||
|
.build();
|
||||||
|
writeFileSync("../output/js/deleted_toc.docx", buffer);
|
||||||
|
const z = new Zip(Buffer.from(buffer));
|
||||||
|
for (const e of z.getEntries()) {
|
||||||
|
if (e.entryName.match(/document.xml/)) {
|
||||||
|
expect(z.readAsText(e)).toMatchSnapshot();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test("should write paragraph delete", () => {
|
test("should write paragraph delete", () => {
|
||||||
const p1 = new w.Paragraph()
|
const p1 = new w.Paragraph()
|
||||||
.addRun(new w.Run().addText("Hello world!!"))
|
.addRun(new w.Run().addText("Hello world!!"))
|
||||||
|
|
Loading…
Reference in New Issue