feat: add comments_json (#773)

main
bokuweb 2024-10-31 18:13:59 +09:00 committed by GitHub
parent 69b4c1a4a3
commit 1f9046d2ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 1 deletions

View File

@ -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();
}

View File

@ -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);

View File

@ -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()
}
}