Skip to content

Commit 366ff60

Browse files
authored
Fix even header types (#682)
* fix: header types * 0.4.9 * fix: title_pg settings * 0.4.11 * fix: update snaps
1 parent 72adfa6 commit 366ff60

File tree

12 files changed

+3859
-12
lines changed

12 files changed

+3859
-12
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## @0.4.11 (1. Mar, 2024)
9+
10+
- Fixed a `title_pg` condition when read.
11+
- Parse `even_and_odd_headers`.
12+
13+
## @0.4.9 (1. Mar, 2024)
14+
15+
- Fixed a js header/footer types.
16+
817
## @0.4.8 (19. Feb, 2024)
918

1019
- Fixed a bug, image in header/footer is not stored in media when read.

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docx-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "docx-rs"
3-
version = "0.4.8"
3+
version = "0.4.11"
44
authors = ["bokuweb <[email protected]>"]
55
repository = "https://github.com/bokuweb/docx-rs"
66
edition = "2018"

docx-core/examples/reader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::fs::File;
44
use std::io::{Read, Write};
55

66
pub fn main() {
7-
let mut file = File::open("./hello.docx").unwrap();
7+
let mut file = File::open("./header-image.docx").unwrap();
88
let mut buf = vec![];
99
file.read_to_end(&mut buf).unwrap();
1010

docx-core/src/documents/document.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ impl Document {
174174
self
175175
}
176176

177+
pub(crate) fn first_header_without_title_pg(mut self, h: Header, rid: &str) -> Self {
178+
self.section_property = self.section_property.first_header_without_title_pg(h, rid);
179+
self
180+
}
181+
177182
pub fn even_header(mut self, h: Header, rid: &str) -> Self {
178183
self.section_property = self.section_property.even_header(h, rid);
179184
self
@@ -189,6 +194,11 @@ impl Document {
189194
self
190195
}
191196

197+
pub(crate) fn first_footer_without_title_pg(mut self, h: Footer, rid: &str) -> Self {
198+
self.section_property = self.section_property.first_footer_without_title_pg(h, rid);
199+
self
200+
}
201+
192202
pub fn even_footer(mut self, h: Footer, rid: &str) -> Self {
193203
self.section_property = self.section_property.even_footer(h, rid);
194204
self

docx-core/src/reader/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,9 @@ pub fn read_docx(buf: &[u8]) -> Result<Docx, ReaderError> {
313313
.clone()
314314
{
315315
if let Some((header, rels)) = headers.get(&h.id) {
316-
docx.document = docx.document.first_header(header.clone(), &h.id);
316+
docx.document = docx
317+
.document
318+
.first_header_without_title_pg(header.clone(), &h.id);
317319
let count = docx.document_rels.header_count + 1;
318320
docx.document_rels.header_count = count;
319321
docx.content_type = docx.content_type.add_header();
@@ -356,7 +358,7 @@ pub fn read_docx(buf: &[u8]) -> Result<Docx, ReaderError> {
356358
.clone()
357359
{
358360
if let Some((footer, rels)) = footers.get(&f.id) {
359-
docx.document = docx.document.first_footer(footer.clone(), &f.id);
361+
docx.document = docx.document.first_footer_without_title_pg(footer.clone(), &f.id);
360362
let count = docx.document_rels.footer_count + 1;
361363
docx.document_rels.footer_count = count;
362364
docx.content_type = docx.content_type.add_footer();
@@ -467,6 +469,7 @@ fn add_images(
467469
if let Some(paths) = media {
468470
for (id, media, ..) in paths {
469471
if let Ok(data) = read_zip(archive, media.to_str().expect("should have media")) {
472+
dbg!("--0-0", &media);
470473
docx = docx.add_image(id, media.to_str().unwrap().to_string(), data);
471474
}
472475
}

docx-core/src/reader/settings.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ impl FromXML for Settings {
4949
}
5050
}
5151
}
52+
XMLElement::EvenAndOddHeaders => {
53+
let val = attributes::read_bool(&attributes);
54+
if val {
55+
settings = settings.even_and_odd_headers();
56+
}
57+
}
5258
XMLElement::AdjustLineHeightInTable => {
5359
settings = settings.adjust_line_height_in_table();
5460
}

docx-wasm/js/json/section-property.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ export type SectionPropertyJSON = {
3939
header?: HeaderJSON;
4040
firstHeaderReference?: HeaderReferenceJSON;
4141
firstHeader?: HeaderJSON;
42-
eventHeaderReference?: HeaderReferenceJSON;
43-
eventHeader?: HeaderJSON;
42+
evenHeaderReference?: HeaderReferenceJSON;
43+
evenHeader?: HeaderJSON;
4444
// footer
4545
footerReference?: FooterReferenceJSON;
4646
footer?: FooterJSON;
4747
firstFooterReference?: FooterReferenceJSON;
4848
firstFooter?: FooterJSON;
49-
eventFooterReference?: FooterReferenceJSON;
50-
eventFooter?: FooterJSON;
49+
evenFooterReference?: FooterReferenceJSON;
50+
evenFooter?: FooterJSON;
5151
};

docx-wasm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "docx-wasm",
3-
"version": "0.4.8",
3+
"version": "0.4.11",
44
"main": "dist/node/index.js",
55
"browser": "dist/web/index.js",
66
"author": "bokuweb <[email protected]>",

0 commit comments

Comments
 (0)