* fix

* fix

* fix

* fix

* fix

* fix

* 0.0.271

* fix

* 0.0.272

Co-authored-by: bokuweb <bokuweb@bokuwebnombp.lan>
main
bokuweb 2022-06-15 23:28:30 +09:00 committed by GitHub
parent 604bdb85f7
commit f08cefff0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
46 changed files with 1445 additions and 24821 deletions

View File

@ -5,7 +5,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## docx-wasm@0.0.262 (7. Jun, 2022)
## docx-wasm@0.0.271, @0.0.272 (15. Jun, 2022)
- [Breaking] Remove default `TableCellMargin`. Please specify if needed.
- Support table cell margins reader.
## docx-wasm@0.0.269, @0.0.270 (14. Jun, 2022)
- Support nested table reader.
## docx-wasm@0.0.268 (13. Jun, 2022)
- Add png image converter
## docx-wasm@0.0.264 (7. Jun, 2022)
- Add `imageData` in `Shape` reader.

View File

@ -163,12 +163,7 @@ mod tests {
let b = Table::new(vec![TableRow::new(vec![])]).build();
assert_eq!(
str::from_utf8(&b).unwrap(),
r#"<w:tbl><w:tblPr><w:tblW w:w="0" w:type="dxa" /><w:jc w:val="left" /><w:tblBorders><w:top w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:left w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:bottom w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:right w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideH w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideV w:val="single" w:sz="2" w:space="0" w:color="000000" /></w:tblBorders><w:tblCellMar>
<w:top w:w="0" w:type="dxa" />
<w:left w:w="55" w:type="dxa" />
<w:bottom w:w="0" w:type="dxa" />
<w:right w:w="55" w:type="dxa" />
</w:tblCellMar></w:tblPr><w:tblGrid /><w:tr><w:trPr /></w:tr></w:tbl>"#
r#"<w:tbl><w:tblPr><w:tblW w:w="0" w:type="dxa" /><w:jc w:val="left" /><w:tblBorders><w:top w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:left w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:bottom w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:right w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideH w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideV w:val="single" w:sz="2" w:space="0" w:color="000000" /></w:tblBorders></w:tblPr><w:tblGrid /><w:tr><w:trPr /></w:tr></w:tbl>"#
);
}
@ -179,12 +174,7 @@ mod tests {
.build();
assert_eq!(
str::from_utf8(&b).unwrap(),
r#"<w:tbl><w:tblPr><w:tblW w:w="0" w:type="dxa" /><w:jc w:val="left" /><w:tblBorders><w:top w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:left w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:bottom w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:right w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideH w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideV w:val="single" w:sz="2" w:space="0" w:color="000000" /></w:tblBorders><w:tblCellMar>
<w:top w:w="0" w:type="dxa" />
<w:left w:w="55" w:type="dxa" />
<w:bottom w:w="0" w:type="dxa" />
<w:right w:w="55" w:type="dxa" />
</w:tblCellMar></w:tblPr><w:tblGrid>
r#"<w:tbl><w:tblPr><w:tblW w:w="0" w:type="dxa" /><w:jc w:val="left" /><w:tblBorders><w:top w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:left w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:bottom w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:right w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideH w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideV w:val="single" w:sz="2" w:space="0" w:color="000000" /></w:tblBorders></w:tblPr><w:tblGrid>
<w:gridCol w:w="100" w:type="dxa" />
<w:gridCol w:w="200" w:type="dxa" />
</w:tblGrid><w:tr><w:trPr /></w:tr></w:tbl>"#
@ -196,7 +186,7 @@ mod tests {
let t = Table::new(vec![]).set_grid(vec![100, 200, 300]);
assert_eq!(
serde_json::to_string(&t).unwrap(),
r#"{"rows":[],"grid":[100,200,300],"hasNumbering":false,"property":{"width":{"width":0,"widthType":"auto"},"justification":"left","borders":{"top":{"borderType":"single","size":2,"color":"000000","position":"top","space":0},"left":{"borderType":"single","size":2,"color":"000000","position":"left","space":0},"bottom":{"borderType":"single","size":2,"color":"000000","position":"bottom","space":0},"right":{"borderType":"single","size":2,"color":"000000","position":"right","space":0},"insideH":{"borderType":"single","size":2,"color":"000000","position":"insideH","space":0},"insideV":{"borderType":"single","size":2,"color":"000000","position":"insideV","space":0}},"margins":{"top":{"val":0,"widthType":"dxa"},"left":{"val":55,"widthType":"dxa"},"bottom":{"val":0,"widthType":"dxa"},"right":{"val":55,"widthType":"dxa"}},"indent":null,"style":null,"layout":null}}"#
r#"{"rows":[],"grid":[100,200,300],"hasNumbering":false,"property":{"width":{"width":0,"widthType":"auto"},"justification":"left","borders":{"top":{"borderType":"single","size":2,"color":"000000","position":"top","space":0},"left":{"borderType":"single","size":2,"color":"000000","position":"left","space":0},"bottom":{"borderType":"single","size":2,"color":"000000","position":"bottom","space":0},"right":{"borderType":"single","size":2,"color":"000000","position":"right","space":0},"insideH":{"borderType":"single","size":2,"color":"000000","position":"insideH","space":0},"insideV":{"borderType":"single","size":2,"color":"000000","position":"insideV","space":0}}}}"#
);
}
}

View File

@ -1,5 +1,5 @@
use wasm_bindgen::prelude::*;
use serde::Serialize;
use wasm_bindgen::prelude::*;
use super::*;
use crate::documents::BuildXML;
@ -13,9 +13,13 @@ pub struct TableProperty {
width: TableWidth,
justification: Justification,
borders: TableBorders,
margins: TableCellMargins,
#[serde(skip_serializing_if = "Option::is_none")]
margins: Option<TableCellMargins>,
#[serde(skip_serializing_if = "Option::is_none")]
indent: Option<TableIndent>,
#[serde(skip_serializing_if = "Option::is_none")]
style: Option<TableStyle>,
#[serde(skip_serializing_if = "Option::is_none")]
layout: Option<TableLayout>,
}
@ -25,7 +29,7 @@ impl Default for TableProperty {
width: TableWidth::new(0, WidthType::Auto),
justification: Justification::new("left"),
borders: TableBorders::new(),
margins: TableCellMargins::new(),
margins: None,
indent: None,
style: None,
layout: None,
@ -61,27 +65,47 @@ impl TableProperty {
}
pub fn set_margins(mut self, margins: TableCellMargins) -> Self {
self.margins = margins;
self.margins = Some(margins);
self
}
pub fn cell_margin_top(mut self, v: usize, t: WidthType) -> Self {
self.margins = self.margins.margin_top(v, t);
if let Some(margins) = self.margins {
self.margins = Some(margins.margin_top(v, t));
} else {
let margins = TableCellMargins::new();
self.margins = Some(margins.margin_top(v, t));
}
self
}
pub fn cell_margin_right(mut self, v: usize, t: WidthType) -> Self {
self.margins = self.margins.margin_right(v, t);
if let Some(margins) = self.margins {
self.margins = Some(margins.margin_right(v, t));
} else {
let margins = TableCellMargins::new();
self.margins = Some(margins.margin_right(v, t));
}
self
}
pub fn cell_margin_bottom(mut self, v: usize, t: WidthType) -> Self {
self.margins = self.margins.margin_bottom(v, t);
if let Some(margins) = self.margins {
self.margins = Some(margins.margin_bottom(v, t));
} else {
let margins = TableCellMargins::new();
self.margins = Some(margins.margin_bottom(v, t));
}
self
}
pub fn cell_margin_left(mut self, v: usize, t: WidthType) -> Self {
self.margins = self.margins.margin_left(v, t);
if let Some(margins) = self.margins {
self.margins = Some(margins.margin_left(v, t));
} else {
let margins = TableCellMargins::new();
self.margins = Some(margins.margin_left(v, t));
}
self
}
@ -123,7 +147,7 @@ impl BuildXML for TableProperty {
.add_child(&self.width)
.add_child(&self.justification)
.add_child(&self.borders)
.add_child(&self.margins)
.add_optional_child(&self.margins)
.add_optional_child(&self.indent)
.add_optional_child(&self.style)
.add_optional_child(&self.layout)
@ -146,12 +170,7 @@ mod tests {
let b = c.build();
assert_eq!(
str::from_utf8(&b).unwrap(),
r#"<w:tblPr><w:tblW w:w="0" w:type="dxa" /><w:jc w:val="left" /><w:tblBorders><w:top w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:left w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:bottom w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:right w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideH w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideV w:val="single" w:sz="2" w:space="0" w:color="000000" /></w:tblBorders><w:tblCellMar>
<w:top w:w="0" w:type="dxa" />
<w:left w:w="55" w:type="dxa" />
<w:bottom w:w="0" w:type="dxa" />
<w:right w:w="55" w:type="dxa" />
</w:tblCellMar></w:tblPr>"#
r#"<w:tblPr><w:tblW w:w="0" w:type="dxa" /><w:jc w:val="left" /><w:tblBorders><w:top w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:left w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:bottom w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:right w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideH w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideV w:val="single" w:sz="2" w:space="0" w:color="000000" /></w:tblBorders></w:tblPr>"#
);
}
@ -160,7 +179,7 @@ mod tests {
let p = TableProperty::new().indent(100);
assert_eq!(
serde_json::to_string(&p).unwrap(),
r#"{"width":{"width":0,"widthType":"auto"},"justification":"left","borders":{"top":{"borderType":"single","size":2,"color":"000000","position":"top","space":0},"left":{"borderType":"single","size":2,"color":"000000","position":"left","space":0},"bottom":{"borderType":"single","size":2,"color":"000000","position":"bottom","space":0},"right":{"borderType":"single","size":2,"color":"000000","position":"right","space":0},"insideH":{"borderType":"single","size":2,"color":"000000","position":"insideH","space":0},"insideV":{"borderType":"single","size":2,"color":"000000","position":"insideV","space":0}},"margins":{"top":{"val":0,"widthType":"dxa"},"left":{"val":55,"widthType":"dxa"},"bottom":{"val":0,"widthType":"dxa"},"right":{"val":55,"widthType":"dxa"}},"indent":{"width":100,"widthType":"dxa"},"style":null,"layout":null}"#
r#"{"width":{"width":0,"widthType":"auto"},"justification":"left","borders":{"top":{"borderType":"single","size":2,"color":"000000","position":"top","space":0},"left":{"borderType":"single","size":2,"color":"000000","position":"left","space":0},"bottom":{"borderType":"single","size":2,"color":"000000","position":"bottom","space":0},"right":{"borderType":"single","size":2,"color":"000000","position":"right","space":0},"insideH":{"borderType":"single","size":2,"color":"000000","position":"insideH","space":0},"insideV":{"borderType":"single","size":2,"color":"000000","position":"insideV","space":0}},"indent":{"width":100,"widthType":"dxa"}}"#
);
}
}

View File

@ -16,8 +16,6 @@ impl ElementReader for TableCell {
attributes, name, ..
}) => {
let e = XMLElement::from_str(&name.local_name).unwrap();
// FIXME: ignore table in table for now. Please support table in table later.
ignore::ignore_element(e.clone(), XMLElement::Table, r);
match e {
XMLElement::Paragraph => {
let p = Paragraph::read(r, &attributes)?;
@ -30,6 +28,11 @@ impl ElementReader for TableCell {
}
continue;
}
XMLElement::Table => {
if let Ok(table) = Table::read(r, &attributes) {
cell = cell.add_table(table)
}
}
_ => {}
}
}

View File

@ -20,11 +20,19 @@ impl ElementReader for TableProperty {
attributes, name, ..
}) => {
let e = XMLElement::from_str(&name.local_name).unwrap();
if let XMLElement::TableBorders = e {
match e {
XMLElement::TableBorders => {
if let Ok(borders) = TableBorders::read(r, &attributes) {
tp = tp.set_borders(borders);
}
}
XMLElement::TableCellMargin => {
if let Ok(margins) = TableCellMargins::read(r, &attributes) {
tp = tp.set_margins(margins);
}
}
_ => {}
}
}
Ok(XmlEvent::EndElement { name, .. }) => {
let e = XMLElement::from_str(&name.local_name).unwrap();

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -6,7 +6,7 @@ import { ShadingJSON } from "./shading";
import { TableLayoutType } from "../table";
import { DeleteJSON, InsertJSON } from "..";
export type TableCellChildJSON = ParagraphJSON;
export type TableCellChildJSON = ParagraphJSON | TableJSON;
export type WidthType = "dxa" | "auto" | "pct" | "nil";

View File

@ -1,6 +1,6 @@
{
"name": "docx-wasm",
"version": "0.0.268",
"version": "0.0.272",
"main": "dist/node/index.js",
"browser": "dist/web/index.js",
"author": "bokuweb <bokuweb12@gmail.com>",

File diff suppressed because one or more lines are too long

View File

@ -148,8 +148,8 @@ describe("reader", () => {
expect(json).toMatchSnapshot();
});
test("should read imagedata in shape", () => {
const buffer = readFileSync("../fixtures/shape/shape.docx");
test("should read nested table", () => {
const buffer = readFileSync("../fixtures/nested_table/nested_table.docx");
const json = w.readDocx(buffer);
expect(json).toMatchSnapshot();
});

Binary file not shown.