fix: ignore comments when there is no comments (#14)

main
bokuweb 2019-12-16 02:19:30 +09:00 committed by GitHub
parent 5d3532bbe3
commit 43ee93aa77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 54 additions and 17 deletions

View File

@ -2,18 +2,25 @@ use crate::documents::BuildXML;
use crate::xml_builder::*; use crate::xml_builder::*;
#[derive(Debug)] #[derive(Debug)]
pub struct DocumentRels {} pub struct DocumentRels {
pub(crate) has_comments: bool,
pub(crate) has_numberings: bool,
}
impl DocumentRels { impl DocumentRels {
pub fn new() -> DocumentRels { pub fn new() -> DocumentRels {
DocumentRels {} DocumentRels {
has_comments: false,
has_numberings: false,
}
} }
} }
impl BuildXML for DocumentRels { impl BuildXML for DocumentRels {
fn build(&self) -> Vec<u8> { fn build(&self) -> Vec<u8> {
let b = XMLBuilder::new(); let mut b = XMLBuilder::new();
b.declaration(None) b = b
.declaration(None)
.open_relationships("http://schemas.openxmlformats.org/package/2006/relationships") .open_relationships("http://schemas.openxmlformats.org/package/2006/relationships")
.relationship( .relationship(
"rId1", "rId1",
@ -22,25 +29,31 @@ impl BuildXML for DocumentRels {
) )
.relationship( .relationship(
"rId2", "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", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable",
"fontTable.xml", "fontTable.xml",
) )
.relationship( .relationship(
"rId5", "rId3",
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings",
"settings.xml", "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()
} }
} }

View File

@ -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); self.comments.add_comments(comments);
} }
} }

View File

@ -340,6 +340,11 @@ export class Table {
* @returns {Table} * @returns {Table}
*/ */
align(v: number): Table; align(v: number): Table;
/**
* @param {number} w
* @returns {Table}
*/
width(w: number): Table;
} }
/** /**
*/ */

View File

@ -972,6 +972,19 @@ export class Table {
const ret = wasm.table_align(ptr, v); const ret = wasm.table_align(ptr, v);
return Table.__wrap(ret); 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);
}
} }
/** /**
*/ */

View File

@ -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_set_grid(a: number, b: number, c: number): number;
export function table_indent(a: number, b: number): number; export function table_indent(a: number, b: number): number;
export function table_align(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 __wbg_numbering_free(a: number): void;
export function createNumbering(a: number): number; export function createNumbering(a: number): number;
export function numbering_add_level(a: number, b: number): number; export function numbering_add_level(a: number, b: number): number;

Binary file not shown.