feat(inbox): docx table cells + grouped pptx shapes (stage 2g)
Two structural regions the office extractors missed, no new dependency: - .docx table cells (they live outside doc.paragraphs); - grouped .pptx shapes (add_group_shape moves a shape inside the group, so the extractor recurses through MSO_SHAPE_TYPE.GROUP to reach it). Each proven by an injection-in-region REJECT plus a clean-region ADMIT. Tests 310 -> 314.
This commit is contained in:
parent
abcdfa3663
commit
6f32e70c6d
2 changed files with 77 additions and 1 deletions
|
|
@ -137,6 +137,13 @@ def _extract_docx_text(fs_path) -> str:
|
|||
doc = Document(str(fs_path))
|
||||
parts = [para.text for para in doc.paragraphs if para.text]
|
||||
|
||||
# Table cells live outside doc.paragraphs — iterate them explicitly.
|
||||
for table in doc.tables:
|
||||
for row in table.rows:
|
||||
for cell in row.cells:
|
||||
if cell.text:
|
||||
parts.append(cell.text)
|
||||
|
||||
cp = doc.core_properties
|
||||
for attr in ("title", "subject", "keywords", "comments", "category", "author"):
|
||||
value = getattr(cp, attr, None)
|
||||
|
|
@ -165,11 +172,21 @@ def _extract_pptx_text(fs_path) -> str:
|
|||
image/shape alt-text. ``python-pptx`` is imported lazily (dev/showcase-scoped).
|
||||
"""
|
||||
from pptx import Presentation
|
||||
from pptx.enum.shapes import MSO_SHAPE_TYPE
|
||||
|
||||
def walk(shapes):
|
||||
# Flatten grouped shapes: add_group_shape moves a shape inside the group,
|
||||
# so only recursion reaches its text/alt-text.
|
||||
for shape in shapes:
|
||||
if shape.shape_type == MSO_SHAPE_TYPE.GROUP:
|
||||
yield from walk(shape.shapes)
|
||||
else:
|
||||
yield shape
|
||||
|
||||
prs = Presentation(str(fs_path))
|
||||
parts: list = []
|
||||
for slide in prs.slides:
|
||||
for shape in slide.shapes:
|
||||
for shape in walk(slide.shapes):
|
||||
if shape.has_text_frame and shape.text_frame.text:
|
||||
parts.append(shape.text_frame.text) # incl. off-slide boxes
|
||||
alt = _shape_alt_text(shape)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue