fix: ignore comments when there is no comments (#14)
parent
5d3532bbe3
commit
43ee93aa77
|
@ -2,18 +2,25 @@ use crate::documents::BuildXML;
|
|||
use crate::xml_builder::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DocumentRels {}
|
||||
pub struct DocumentRels {
|
||||
pub(crate) has_comments: bool,
|
||||
pub(crate) has_numberings: bool,
|
||||
}
|
||||
|
||||
impl DocumentRels {
|
||||
pub fn new() -> DocumentRels {
|
||||
DocumentRels {}
|
||||
DocumentRels {
|
||||
has_comments: false,
|
||||
has_numberings: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BuildXML for DocumentRels {
|
||||
fn build(&self) -> Vec<u8> {
|
||||
let b = XMLBuilder::new();
|
||||
b.declaration(None)
|
||||
let mut b = XMLBuilder::new();
|
||||
b = b
|
||||
.declaration(None)
|
||||
.open_relationships("http://schemas.openxmlformats.org/package/2006/relationships")
|
||||
.relationship(
|
||||
"rId1",
|
||||
|
@ -22,25 +29,31 @@ impl BuildXML for DocumentRels {
|
|||
)
|
||||
.relationship(
|
||||
"rId2",
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering",
|
||||
"numbering.xml",
|
||||
)
|
||||
.relationship(
|
||||
"rId3",
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",
|
||||
"comments.xml",
|
||||
)
|
||||
.relationship(
|
||||
"rId4",
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable",
|
||||
"fontTable.xml",
|
||||
)
|
||||
.relationship(
|
||||
"rId5",
|
||||
"rId3",
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings",
|
||||
"settings.xml",
|
||||
);
|
||||
|
||||
if self.has_comments {
|
||||
b = b.relationship(
|
||||
"rId4",
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",
|
||||
"comments.xml",
|
||||
)
|
||||
.close()
|
||||
.build()
|
||||
}
|
||||
|
||||
if self.has_numberings {
|
||||
b = b.relationship(
|
||||
"rId5",
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering",
|
||||
"numbering.xml",
|
||||
)
|
||||
}
|
||||
|
||||
b.close().build()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -154,6 +154,11 @@ impl Docx {
|
|||
_ => {}
|
||||
}
|
||||
}
|
||||
// If this document has comments, set comments.xml to document_rels.
|
||||
// This is because comments.xml without comment cause an error on word online.
|
||||
if comments.len() > 0 {
|
||||
self.document_rels.has_comments = true;
|
||||
}
|
||||
self.comments.add_comments(comments);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -340,6 +340,11 @@ export class Table {
|
|||
* @returns {Table}
|
||||
*/
|
||||
align(v: number): Table;
|
||||
/**
|
||||
* @param {number} w
|
||||
* @returns {Table}
|
||||
*/
|
||||
width(w: number): Table;
|
||||
}
|
||||
/**
|
||||
*/
|
||||
|
|
|
@ -972,6 +972,19 @@ export class Table {
|
|||
const ret = wasm.table_align(ptr, v);
|
||||
return Table.__wrap(ret);
|
||||
}
|
||||
/**
|
||||
* @param {number} w
|
||||
* @returns {Table}
|
||||
*/
|
||||
width(w) {
|
||||
if (this.ptr == 0) throw new Error('Attempt to use a moved value');
|
||||
const ptr = this.ptr;
|
||||
this.ptr = 0;
|
||||
_assertNum(ptr);
|
||||
_assertNum(w);
|
||||
const ret = wasm.table_width(ptr, w);
|
||||
return Table.__wrap(ret);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
|
|
|
@ -44,6 +44,7 @@ export function table_add_row(a: number, b: number): number;
|
|||
export function table_set_grid(a: number, b: number, c: number): number;
|
||||
export function table_indent(a: number, b: number): number;
|
||||
export function table_align(a: number, b: number): number;
|
||||
export function table_width(a: number, b: number): number;
|
||||
export function __wbg_numbering_free(a: number): void;
|
||||
export function createNumbering(a: number): number;
|
||||
export function numbering_add_level(a: number, b: number): number;
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue