Skip to content

Commit

Permalink
feat: add comments_json (#773)
Browse files Browse the repository at this point in the history
  • Loading branch information
bokuweb authored Oct 31, 2024
1 parent 69b4c1a commit 1f9046d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docx-core/src/documents/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
9 changes: 8 additions & 1 deletion docx-wasm/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions docx-wasm/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

0 comments on commit 1f9046d

Please sign in to comment.