diff --git a/CHANGELOG.md b/CHANGELOG.md index aee7c14..b5df8a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## docx-wasm@0.0.217 (21. December, 2021) + +- Fix `strike` API for JS. + ## docx-wasm@0.0.216 (21. December, 2021) - Support `strike` for run. diff --git a/docx-wasm/js/index.ts b/docx-wasm/js/index.ts index e32cf58..0472f1f 100644 --- a/docx-wasm/js/index.ts +++ b/docx-wasm/js/index.ts @@ -298,6 +298,10 @@ export class Docx { run = run.italic(); } + if (r.property.strike) { + run = run.strike(); + } + if (r.property.underline) { run = run.underline(r.property.underline); } diff --git a/docx-wasm/js/run.ts b/docx-wasm/js/run.ts index 786c264..16f9f61 100644 --- a/docx-wasm/js/run.ts +++ b/docx-wasm/js/run.ts @@ -22,6 +22,7 @@ export type RunProperty = { vertAlign?: VertAlignType; bold?: boolean; italic?: boolean; + strike?: boolean; underline?: string; vanish?: boolean; fonts?: RunFonts; @@ -109,6 +110,11 @@ export class Run { return this; } + strike() { + this.property = { ...this.property, strike: true }; + return this; + } + italic() { this.property = { ...this.property, italic: true }; return this; diff --git a/docx-wasm/package.json b/docx-wasm/package.json index 088d1a8..c6e6528 100644 --- a/docx-wasm/package.json +++ b/docx-wasm/package.json @@ -1,6 +1,6 @@ { "name": "docx-wasm", - "version": "0.0.216", + "version": "0.0.217", "main": "dist/node/index.js", "browser": "dist/web/index.js", "author": "bokuweb ", diff --git a/docx-wasm/src/run.rs b/docx-wasm/src/run.rs index 97f0ac8..46a859b 100644 --- a/docx-wasm/src/run.rs +++ b/docx-wasm/src/run.rs @@ -66,6 +66,11 @@ impl Run { self } + pub fn strike(mut self) -> Run { + self.0.run_property = self.0.run_property.strike(); + self + } + pub fn underline(mut self, line_type: &str) -> Run { self.0.run_property = self.0.run_property.underline(line_type); self diff --git a/docx-wasm/test/__snapshots__/index.test.js.snap b/docx-wasm/test/__snapshots__/index.test.js.snap index 1ff2960..2e3a2d1 100644 --- a/docx-wasm/test/__snapshots__/index.test.js.snap +++ b/docx-wasm/test/__snapshots__/index.test.js.snap @@ -23788,6 +23788,30 @@ exports[`writer should write page size 3`] = ` " `; +exports[`writer should write strike 1`] = ` +" + + + + + +" +`; + +exports[`writer should write strike 2`] = ` +" + + Hello world!! +" +`; + +exports[`writer should write strike 3`] = ` +" + + +" +`; + exports[`writer should write table layout 1`] = ` " diff --git a/docx-wasm/test/index.test.js b/docx-wasm/test/index.test.js index 5419287..6e244ec 100644 --- a/docx-wasm/test/index.test.js +++ b/docx-wasm/test/index.test.js @@ -112,6 +112,20 @@ describe("writer", () => { } }); + test("should write strike", () => { + const p = new w.Paragraph().addRun( + new w.Run().addText("Hello world!!").strike() + ); + const buffer = new w.Docx().addParagraph(p).build(); + 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(); + } + } + writeFileSync("../output/strike.docx", buffer); + }); + test("should write lvlOverride with level", () => { const p = new w.Paragraph() .addRun(new w.Run().addText("Hello world!!"))