From 1f0877bbad383d73720cfef6e9d86a8a456d153b Mon Sep 17 00:00:00 2001 From: bokuweb Date: Mon, 13 Jun 2022 19:02:19 +0900 Subject: [PATCH] fix: collect images in nested table (#493) * fix: collect images in nested table * fix Co-authored-by: bokuweb --- docx-core/src/documents/mod.rs | 29 +++++++++++++++++++++++++++-- docx-wasm/package.json | 2 +- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/docx-core/src/documents/mod.rs b/docx-core/src/documents/mod.rs index 5b147c7..936852f 100644 --- a/docx-core/src/documents/mod.rs +++ b/docx-core/src/documents/mod.rs @@ -863,8 +863,12 @@ impl Docx { &mut image_bufs, ); } - TableCellContent::Table(_) => { - // TODO: support comment + TableCellContent::Table(table) => { + collect_images_from_table( + table, + &mut images, + &mut image_bufs, + ); } } } @@ -960,6 +964,27 @@ fn collect_images_from_paragraph( } } +fn collect_images_from_table( + table: &mut Table, + images: &mut Vec<(String, String)>, + image_bufs: &mut Vec<(String, Vec)>, +) { + for TableChild::TableRow(row) in &mut table.rows { + for TableRowChild::TableCell(cell) in &mut row.cells { + for content in &mut cell.children { + match content { + TableCellContent::Paragraph(paragraph) => { + collect_images_from_paragraph(paragraph, images, image_bufs); + } + TableCellContent::Table(table) => { + collect_images_from_table(table, images, image_bufs) + } + } + } + } + } +} + fn update_document_by_toc( document_children: Vec, styles: &Styles, diff --git a/docx-wasm/package.json b/docx-wasm/package.json index ea17483..f231e55 100644 --- a/docx-wasm/package.json +++ b/docx-wasm/package.json @@ -1,6 +1,6 @@ { "name": "docx-wasm", - "version": "0.0.264", + "version": "0.0.265", "main": "dist/node/index.js", "browser": "dist/web/index.js", "author": "bokuweb ",