diff --git a/docx-core/src/documents/mod.rs b/docx-core/src/documents/mod.rs index b8d505a..c476bf4 100644 --- a/docx-core/src/documents/mod.rs +++ b/docx-core/src/documents/mod.rs @@ -652,6 +652,13 @@ impl Docx { serde_json::to_string_pretty(&self).unwrap() } + // Internal: for docx-wasm + pub fn comments_json(&mut self) -> String { + self.reset(); + self.update_dependencies(); + serde_json::to_string_pretty(&self.comments.comments).unwrap() + } + fn reset(&self) { crate::reset_para_id(); } diff --git a/docx-wasm/js/index.ts b/docx-wasm/js/index.ts index 7b0caec..e9fe6a0 100644 --- a/docx-wasm/js/index.ts +++ b/docx-wasm/js/index.ts @@ -21,7 +21,7 @@ import { PageMargin, PageOrientationType, } from "./section-property"; -import { DocGridType, DocxJSON } from "./json"; +import { CommentJSON, DocGridType, DocxJSON } from "./json"; import * as wasm from "./pkg"; import { Level } from "./level"; @@ -626,6 +626,13 @@ export class Docx { return JSON.parse(json) as DocxJSON; } + commentsJson() { + const docx = this.createDocx(); + const json = docx.comments_json(); + docx.free(); + return JSON.parse(json) as CommentJSON[]; + } + build() { const docx = this.createDocx(); const buf = docx.build(this.hasNumberings); diff --git a/docx-wasm/src/doc.rs b/docx-wasm/src/doc.rs index b1b8828..7e2ec45 100644 --- a/docx-wasm/src/doc.rs +++ b/docx-wasm/src/doc.rs @@ -216,4 +216,8 @@ impl Docx { pub fn json_with_update_comments(&mut self) -> String { self.0.json_with_update_comments() } + + pub fn comments_json(&mut self) -> String { + self.0.comments_json() + } }