Process PowerPoint presentation
(self, file_path: str)
| 6 | """Processor for PowerPoint (PPTX) documents""" |
| 7 | |
| 8 | def process(self, file_path: str) -> StructuredDocument: |
| 9 | """Process PowerPoint presentation""" |
| 10 | document = StructuredDocument( |
| 11 | title=Path(file_path).stem, |
| 12 | source_file=file_path, |
| 13 | doc_type=DocumentType.POWERPOINT |
| 14 | ) |
| 15 | |
| 16 | try: |
| 17 | # Open presentation |
| 18 | presentation = Presentation(file_path) |
| 19 | |
| 20 | # Storage for markdown output |
| 21 | markdown_parts = [] |
| 22 | markdown_parts.append(f"# {Path(file_path).stem}\n\n") |
| 23 | |
| 24 | # Process each slide |
| 25 | for i, slide in enumerate(presentation.slides): |
| 26 | # Create section for each slide |
| 27 | slide_section = DocumentSection(title=f"Slide {i+1}", level=1) |
| 28 | slide_section.metadata["slide_number"] = i+1 |
| 29 | |
| 30 | # Add slide title to markdown |
| 31 | markdown_parts.append(f"## Slide {i+1}\n\n") |
| 32 | |
| 33 | # Process slide title if available |
| 34 | if slide.shapes.title: |
| 35 | title_text = slide.shapes.title.text |
| 36 | markdown_parts.append(f"### {title_text}\n\n") |
| 37 | |
| 38 | title_element = DocumentElement( |
| 39 | content=title_text, |
| 40 | element_type="heading", |
| 41 | metadata={"level": 3} |
| 42 | ) |
| 43 | slide_section.add_element(title_element) |
| 44 | |
| 45 | # Process text elements |
| 46 | for shape in slide.shapes: |
| 47 | if hasattr(shape, "text") and shape.text.strip() and shape != slide.shapes.title: |
| 48 | shape_text = shape.text.strip() |
| 49 | # Skip if it's same as title |
| 50 | if slide.shapes.title and shape_text == slide.shapes.title.text: |
| 51 | continue |
| 52 | |
| 53 | markdown_parts.append(f"{shape_text}\n\n") |
| 54 | |
| 55 | # Add text as paragraph |
| 56 | text_element = DocumentElement( |
| 57 | content=shape_text, |
| 58 | element_type="paragraph" |
| 59 | ) |
| 60 | slide_section.add_element(text_element) |
| 61 | |
| 62 | # Add notes if available |
| 63 | if slide.has_notes_slide and slide.notes_slide.notes_text_frame.text.strip(): |
| 64 | notes_text = slide.notes_slide.notes_text_frame.text.strip() |
| 65 | markdown_parts.append(f"**Notes:**\n\n{notes_text}\n\n") |
nothing calls this directly
no test coverage detected