From c89c42dbe23659c7b9264d111d9a0d636db30052 Mon Sep 17 00:00:00 2001 From: bokuweb Date: Wed, 19 Jan 2022 18:55:23 +0900 Subject: [PATCH] 0.0.230 (#413) * fix: del and ins * fix --- docx-wasm/js/index.ts | 14 ++++++++ docx-wasm/package.json | 2 +- docx-wasm/src/paragraph.rs | 10 ++++++ .../test/__snapshots__/index.test.js.snap | 27 ++++++++++++++++ docx-wasm/test/index.test.js | 32 ++++++++++++++++--- 5 files changed, 80 insertions(+), 5 deletions(-) diff --git a/docx-wasm/js/index.ts b/docx-wasm/js/index.ts index 9f4dd9a..e2ebdf3 100644 --- a/docx-wasm/js/index.ts +++ b/docx-wasm/js/index.ts @@ -575,6 +575,20 @@ export class Docx { paragraph = paragraph.size(p.property.runProperty.size); } + if (p.property.runProperty.del) { + paragraph = paragraph.delete( + p.property.runProperty.del.author, + p.property.runProperty.del.date + ); + } + + if (p.property.runProperty.ins) { + paragraph = paragraph.insert( + p.property.runProperty.ins.author, + p.property.runProperty.ins.date + ); + } + if (p.property.runProperty.fonts) { let f = wasm.createRunFonts(); if (p.property.runProperty.fonts._ascii) { diff --git a/docx-wasm/package.json b/docx-wasm/package.json index d353ca3..c5108c0 100644 --- a/docx-wasm/package.json +++ b/docx-wasm/package.json @@ -1,6 +1,6 @@ { "name": "docx-wasm", - "version": "0.0.229", + "version": "0.0.230", "main": "dist/node/index.js", "browser": "dist/web/index.js", "author": "bokuweb ", diff --git a/docx-wasm/src/paragraph.rs b/docx-wasm/src/paragraph.rs index 127df7a..0da8eb6 100644 --- a/docx-wasm/src/paragraph.rs +++ b/docx-wasm/src/paragraph.rs @@ -202,6 +202,16 @@ impl Paragraph { self } + pub fn delete(mut self, author: &str, date: &str) -> Self { + self.0 = self.0.delete(author, date); + self + } + + pub fn insert(mut self, author: &str, date: &str) -> Self { + self.0 = self.0.insert(author, date); + self + } + pub fn paragraph_property_change(mut self, p: ParagraphPropertyChange) -> Self { self.0.property = self.0.property.paragraph_property_change(p.take()); self diff --git a/docx-wasm/test/__snapshots__/index.test.js.snap b/docx-wasm/test/__snapshots__/index.test.js.snap index 856bf4d..6c6e8c5 100644 --- a/docx-wasm/test/__snapshots__/index.test.js.snap +++ b/docx-wasm/test/__snapshots__/index.test.js.snap @@ -42669,6 +42669,33 @@ exports[`writer should write page size 3`] = ` " `; +exports[`writer should write paragraph delete 1`] = ` +" + + + + + + +" +`; + +exports[`writer should write paragraph delete 2`] = ` +" + + Hello world!!Foo +" +`; + +exports[`writer should write paragraph delete 3`] = ` +" + + + + +" +`; + exports[`writer should write strike 1`] = ` " diff --git a/docx-wasm/test/index.test.js b/docx-wasm/test/index.test.js index 8054757..4e7db08 100644 --- a/docx-wasm/test/index.test.js +++ b/docx-wasm/test/index.test.js @@ -637,10 +637,34 @@ describe("writer", () => { const num = new w.Numbering(1, 0); const buffer = new w.Docx().addParagraph(p).addNumbering(num).build(); - writeFileSync( - "../output/js/pprchange_with_deleted_numbering.docx", - buffer - ); + writeFileSync("../output/js/pprchange_with_deleted_numbering.docx", buffer); + + const z = new Zip(Buffer.from(buffer)); + for (const e of z.getEntries()) { + if (e.entryName.match(/document.xml|numbering.xml/)) { + expect(z.readAsText(e)).toMatchSnapshot(); + } + } + }); + + test("should write paragraph delete", () => { + const p1 = new w.Paragraph() + .addRun(new w.Run().addText("Hello world!!")) + .numbering(1, 0) + .delete("bokuweb", "2021-12-23T18:16:00Z"); + const p2 = new w.Paragraph() + .addRun(new w.Run().addText("Foo")) + .numbering(1, 0); + + const num = new w.Numbering(1, 0); + + const buffer = new w.Docx() + .addParagraph(p1) + .addParagraph(p2) + .addNumbering(num) + .build(); + + writeFileSync("../output/js/paragraph_delete.docx", buffer); const z = new Zip(Buffer.from(buffer)); for (const e of z.getEntries()) {