parent
856b2b6660
commit
17c669bdde
|
@ -88,7 +88,7 @@ jobs:
|
||||||
- uses: actions-rs/toolchain@v1
|
- uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
profile: minimal
|
profile: minimal
|
||||||
toolchain: stable
|
toolchain: 1.45.1
|
||||||
override: true
|
override: true
|
||||||
- run: rustup component add clippy
|
- run: rustup component add clippy
|
||||||
- uses: actions-rs/cargo@v1
|
- uses: actions-rs/cargo@v1
|
||||||
|
|
|
@ -10,6 +10,8 @@ use crate::xml_builder::*;
|
||||||
pub enum InsertChild {
|
pub enum InsertChild {
|
||||||
Run(Box<Run>),
|
Run(Box<Run>),
|
||||||
Delete(Delete),
|
Delete(Delete),
|
||||||
|
CommentStart(Box<CommentRangeStart>),
|
||||||
|
CommentEnd(CommentRangeEnd),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BuildXML for InsertChild {
|
impl BuildXML for InsertChild {
|
||||||
|
@ -17,6 +19,8 @@ impl BuildXML for InsertChild {
|
||||||
match self {
|
match self {
|
||||||
InsertChild::Run(v) => v.build(),
|
InsertChild::Run(v) => v.build(),
|
||||||
InsertChild::Delete(v) => v.build(),
|
InsertChild::Delete(v) => v.build(),
|
||||||
|
InsertChild::CommentStart(v) => v.build(),
|
||||||
|
InsertChild::CommentEnd(v) => v.build(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +43,18 @@ impl Serialize for InsertChild {
|
||||||
t.serialize_field("data", r)?;
|
t.serialize_field("data", r)?;
|
||||||
t.end()
|
t.end()
|
||||||
}
|
}
|
||||||
|
InsertChild::CommentStart(ref r) => {
|
||||||
|
let mut t = serializer.serialize_struct("CommentRangeStart", 2)?;
|
||||||
|
t.serialize_field("type", "commentRangeStart")?;
|
||||||
|
t.serialize_field("data", r)?;
|
||||||
|
t.end()
|
||||||
|
}
|
||||||
|
InsertChild::CommentEnd(ref r) => {
|
||||||
|
let mut t = serializer.serialize_struct("CommentRangeEnd", 2)?;
|
||||||
|
t.serialize_field("type", "commentRangeEnd")?;
|
||||||
|
t.serialize_field("data", r)?;
|
||||||
|
t.end()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,6 +112,19 @@ impl Insert {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_comment_start(mut self, comment: Comment) -> Self {
|
||||||
|
self.children.push(InsertChild::CommentStart(Box::new(
|
||||||
|
CommentRangeStart::new(comment),
|
||||||
|
)));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_comment_end(mut self, id: usize) -> Self {
|
||||||
|
self.children
|
||||||
|
.push(InsertChild::CommentEnd(CommentRangeEnd::new(id)));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn author(mut self, author: impl Into<String>) -> Insert {
|
pub fn author(mut self, author: impl Into<String>) -> Insert {
|
||||||
self.author = author.into();
|
self.author = author.into();
|
||||||
self
|
self
|
||||||
|
|
|
@ -431,6 +431,19 @@ impl Docx {
|
||||||
c.as_mut().comment(comment);
|
c.as_mut().comment(comment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let ParagraphChild::Insert(ref mut insert) = child {
|
||||||
|
for child in &mut insert.children {
|
||||||
|
if let InsertChild::CommentStart(ref mut c) = child {
|
||||||
|
let comment_id = c.get_id();
|
||||||
|
if let Some(comment) =
|
||||||
|
comments.iter().find(|c| c.id() == comment_id)
|
||||||
|
{
|
||||||
|
let comment = comment.clone();
|
||||||
|
c.as_mut().comment(comment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DocumentChild::Table(table) => {
|
DocumentChild::Table(table) => {
|
||||||
|
@ -449,6 +462,22 @@ impl Docx {
|
||||||
c.as_mut().comment(comment);
|
c.as_mut().comment(comment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let ParagraphChild::Insert(ref mut insert) = child {
|
||||||
|
for child in &mut insert.children {
|
||||||
|
if let InsertChild::CommentStart(ref mut c) =
|
||||||
|
child
|
||||||
|
{
|
||||||
|
let comment_id = c.get_id();
|
||||||
|
if let Some(comment) = comments
|
||||||
|
.iter()
|
||||||
|
.find(|c| c.id() == comment_id)
|
||||||
|
{
|
||||||
|
let comment = comment.clone();
|
||||||
|
c.as_mut().comment(comment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,18 +11,33 @@ impl ElementReader for Insert {
|
||||||
r: &mut EventReader<R>,
|
r: &mut EventReader<R>,
|
||||||
attrs: &[OwnedAttribute],
|
attrs: &[OwnedAttribute],
|
||||||
) -> Result<Self, ReaderError> {
|
) -> Result<Self, ReaderError> {
|
||||||
let mut children: Vec<InsertChild> = vec![];
|
let mut ins = Insert::new_with_empty();
|
||||||
loop {
|
loop {
|
||||||
let e = r.next();
|
let e = r.next();
|
||||||
match e {
|
match e {
|
||||||
Ok(XmlEvent::StartElement { name, .. }) => {
|
Ok(XmlEvent::StartElement {
|
||||||
|
name, attributes, ..
|
||||||
|
}) => {
|
||||||
let e = XMLElement::from_str(&name.local_name).unwrap();
|
let e = XMLElement::from_str(&name.local_name).unwrap();
|
||||||
match e {
|
match e {
|
||||||
XMLElement::Run => {
|
XMLElement::Run => ins = ins.add_run(Run::read(r, attrs)?),
|
||||||
children.push(InsertChild::Run(Box::new(Run::read(r, attrs)?)))
|
XMLElement::Delete => ins = ins.add_delete(Delete::read(r, attrs)?),
|
||||||
|
XMLElement::CommentRangeStart => {
|
||||||
|
if let Some(id) = read(&attributes, "id") {
|
||||||
|
if let Ok(id) = usize::from_str(&id) {
|
||||||
|
let comment = Comment::new(id);
|
||||||
|
ins = ins.add_comment_start(comment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
XMLElement::Delete => {
|
XMLElement::CommentRangeEnd => {
|
||||||
children.push(InsertChild::Delete(Delete::read(r, attrs)?))
|
if let Some(id) = read(&attributes, "id") {
|
||||||
|
if let Ok(id) = usize::from_str(&id) {
|
||||||
|
ins = ins.add_comment_end(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +45,6 @@ impl ElementReader for Insert {
|
||||||
Ok(XmlEvent::EndElement { name, .. }) => {
|
Ok(XmlEvent::EndElement { name, .. }) => {
|
||||||
let e = XMLElement::from_str(&name.local_name).unwrap();
|
let e = XMLElement::from_str(&name.local_name).unwrap();
|
||||||
if e == XMLElement::Insert {
|
if e == XMLElement::Insert {
|
||||||
let mut ins = Insert::new_with_empty();
|
|
||||||
for attr in attrs {
|
for attr in attrs {
|
||||||
let local_name = &attr.name.local_name;
|
let local_name = &attr.name.local_name;
|
||||||
if local_name == "author" {
|
if local_name == "author" {
|
||||||
|
@ -39,9 +53,6 @@ impl ElementReader for Insert {
|
||||||
ins = ins.date(&attr.value);
|
ins = ins.date(&attr.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for c in children.into_iter() {
|
|
||||||
ins = ins.add_child(c);
|
|
||||||
}
|
|
||||||
return Ok(ins);
|
return Ok(ins);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,12 @@ export type ParagraphJSON = {
|
||||||
export type InsertJSON = {
|
export type InsertJSON = {
|
||||||
type: "insert";
|
type: "insert";
|
||||||
data: {
|
data: {
|
||||||
children: (DeleteJSON | RunJSON)[];
|
children: (
|
||||||
|
| DeleteJSON
|
||||||
|
| RunJSON
|
||||||
|
| CommentRangeStartJSON
|
||||||
|
| CommentRangeEndJSON
|
||||||
|
)[];
|
||||||
author: string;
|
author: string;
|
||||||
data: string;
|
data: string;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "docx-wasm",
|
"name": "docx-wasm",
|
||||||
"version": "0.0.134",
|
"version": "0.0.136",
|
||||||
"main": "dist/node/index.js",
|
"main": "dist/node/index.js",
|
||||||
"browser": "dist/web/index.js",
|
"browser": "dist/web/index.js",
|
||||||
"author": "bokuweb <bokuweb12@gmail.com>",
|
"author": "bokuweb <bokuweb12@gmail.com>",
|
||||||
|
|
Loading…
Reference in New Issue