-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: Prepare extended comments * feat: Append paraId for paragraph * feat: Support comment extended * chore: Add fixture * fix: browser example * fix: test * update snaps
- Loading branch information
Showing
82 changed files
with
1,115 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use docx_rs::*; | ||
|
||
pub fn main() -> Result<(), DocxError> { | ||
let path = std::path::Path::new("./output/nested_comment.docx"); | ||
let file = std::fs::File::create(&path).unwrap(); | ||
Docx::new() | ||
.add_paragraph( | ||
Paragraph::new() | ||
.add_comment_start( | ||
Comment::new(1) | ||
.author("bokuweb") | ||
.date("2019-01-01T00:00:00Z") | ||
.paragraph(Paragraph::new().add_run(Run::new().add_text("Hello"))), | ||
) | ||
.add_comment_end(1) | ||
.add_comment_start( | ||
Comment::new(2) | ||
.author("bokuweb") | ||
.date("2019-01-02T00:00:00Z") | ||
.parent_comment_id(1) | ||
.paragraph(Paragraph::new().add_run(Run::new().add_text("World"))), | ||
) | ||
.add_comment_end(2) | ||
.add_comment_start( | ||
Comment::new(3) | ||
.author("bokuweb") | ||
.date("2019-01-02T00:00:00Z") | ||
.parent_comment_id(1) | ||
.paragraph(Paragraph::new().add_run(Run::new().add_text("!!!!!"))), | ||
) | ||
.add_comment_end(3), | ||
) | ||
.build() | ||
.pack(file)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use serde::Serialize; | ||
|
||
use super::*; | ||
use crate::documents::BuildXML; | ||
use crate::xml_builder::*; | ||
|
||
// i.e. <w15:commentEx w15:paraId="00000001" w15:paraIdParent="57D1BD7C" w15:done="0"/> | ||
|
||
#[derive(Debug, Clone, PartialEq, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct CommentsExtended { | ||
children: Vec<CommentExtended>, | ||
} | ||
|
||
impl CommentsExtended { | ||
pub fn new() -> CommentsExtended { | ||
Default::default() | ||
} | ||
|
||
pub fn add_comments_extended(&mut self, c: Vec<CommentExtended>) { | ||
self.children = c; | ||
} | ||
} | ||
|
||
impl Default for CommentsExtended { | ||
fn default() -> Self { | ||
Self { children: vec![] } | ||
} | ||
} | ||
|
||
impl BuildXML for CommentsExtended { | ||
fn build(&self) -> Vec<u8> { | ||
let mut b = XMLBuilder::new(); | ||
b = b.open_comments_extended(); | ||
|
||
for c in &self.children { | ||
b = b.add_child(c) | ||
} | ||
b.close().build() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
use super::*; | ||
use insta::assert_snapshot; | ||
use std::str; | ||
|
||
#[test] | ||
fn test_settings() { | ||
let mut c = CommentsExtended::new(); | ||
c.add_comments_extended(vec![CommentExtended::new("123")]); | ||
let b = c.build(); | ||
assert_snapshot!("comments_extended_snapshot", str::from_utf8(&b).unwrap()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use serde::Serialize; | ||
|
||
use crate::documents::BuildXML; | ||
use crate::xml_builder::*; | ||
|
||
#[derive(Debug, Clone, PartialEq, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct CommentExtended { | ||
paragraph_id: String, | ||
done: bool, | ||
parent_paragraph_id: Option<String>, | ||
} | ||
|
||
impl CommentExtended { | ||
pub fn new(paragraph_id: impl Into<String>) -> CommentExtended { | ||
Self { | ||
paragraph_id: paragraph_id.into(), | ||
done: false, | ||
parent_paragraph_id: None, | ||
} | ||
} | ||
|
||
pub fn done(mut self) -> CommentExtended { | ||
self.done = true; | ||
self | ||
} | ||
|
||
pub fn parent_paragraph_id(mut self, id: impl Into<String>) -> CommentExtended { | ||
self.parent_paragraph_id = Some(id.into()); | ||
self | ||
} | ||
} | ||
|
||
impl BuildXML for CommentExtended { | ||
fn build(&self) -> Vec<u8> { | ||
XMLBuilder::new() | ||
.comment_extended(&self.paragraph_id, self.done, &self.parent_paragraph_id) | ||
.build() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.