Read section props in paragraph (#533)

* feat: support section property in ppr

* spec: Add snao

* fix

* fix
main
bokuweb 2022-09-09 11:52:53 +09:00 committed by GitHub
parent 2b6344f31b
commit 726d0958c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 61795 additions and 2 deletions

View File

@ -235,6 +235,11 @@ impl Paragraph {
self
}
pub fn section_property(mut self, s: SectionProperty) -> Self {
self.property = self.property.section_property(s);
self
}
pub fn add_tab(mut self, t: Tab) -> Self {
self.property = self.property.add_tab(t);
self

View File

@ -29,6 +29,8 @@ pub struct ParagraphProperty {
pub widow_control: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub outline_lvl: Option<OutlineLvl>,
#[serde(skip_serializing_if = "Option::is_none")]
pub section_property: Option<SectionProperty>,
pub tabs: Vec<Tab>,
// read only
#[serde(skip_serializing_if = "Option::is_none")]
@ -116,6 +118,11 @@ impl ParagraphProperty {
self
}
pub fn section_property(mut self, s: SectionProperty) -> Self {
self.section_property = Some(s);
self
}
pub fn paragraph_property_change(mut self, p: ParagraphPropertyChange) -> Self {
self.paragraph_property_change = Some(p);
self

View File

@ -105,6 +105,11 @@ impl ElementReader for ParagraphProperty {
p.paragraph_property_change = Some(ppr_change);
}
}
XMLElement::SectionProperty => {
if let Ok(sp) = SectionProperty::read(r, &attributes) {
p.section_property = Some(sp);
}
}
_ => {}
}
}

View File

@ -1,6 +1,10 @@
import { RunJSON, RunPropertyJSON } from "./run";
import { IndentJSON } from "./indent";
import { CommentRangeStartJSON, CommentRangeEndJSON } from "..";
import {
CommentRangeStartJSON,
CommentRangeEndJSON,
SectionPropertyJSON,
} from "..";
import { LineSpacingJSON } from "./line_spacing";
export type ParagraphChildJSON =
@ -45,6 +49,7 @@ export type ParagraphPropertyJSON = {
date: string;
property: ParagraphPropertyJSON;
};
sectionProperty?: SectionPropertyJSON;
};
export type ParagraphJSON = {

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -165,6 +165,12 @@ describe("reader", () => {
const json = w.readDocx(buffer);
expect(json).toMatchSnapshot();
});
test("should read sectionProperty in ppr", () => {
const buffer = readFileSync("../fixtures/section_property_in_ppr/section_property_in_ppr.docx");
const json = w.readDocx(buffer);
expect(json).toMatchSnapshot();
});
});
describe("writer", () => {