Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion haystack/components/converters/pptx.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@ def _process_paragraph(self, paragraph: "_Paragraph") -> str:
if self.link_format == "none":
return paragraph.text
parts = []
for run in paragraph.runs:
runs = {run._r: run for run in paragraph.runs}
for content in paragraph._element.content_children:
run = runs.get(content)
if run is None:
if content.text == "\v":
parts.append("\v")
continue
if run.hyperlink and run.hyperlink.address:
if self.link_format == "markdown":
parts.append(f"[{run.text}]({run.hyperlink.address})")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
Fixed ``PPTXToDocument`` dropping soft line breaks from paragraphs when ``link_format`` is
``"markdown"`` or ``"plain"``. Soft line breaks are now preserved as vertical tabs
(``"\v"``), matching the behavior of the default ``"none"`` format.
17 changes: 17 additions & 0 deletions test/components/converters/test_pptx_to_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
#
# SPDX-License-Identifier: Apache-2.0

import io
import logging
import os
from pathlib import Path

import pytest
from pptx import Presentation
from pptx.util import Inches

from haystack.components.converters.pptx import PPTXToDocument
from haystack.dataclasses import ByteStream
Expand Down Expand Up @@ -123,3 +126,17 @@ def test_no_link_extraction(self, test_files_path):

assert "https://example.com" not in content
assert "Example" in content

@pytest.mark.parametrize("link_format", ["markdown", "plain"])
def test_soft_line_break_preserved(self, link_format):
presentation = Presentation()
slide = presentation.slides.add_slide(presentation.slide_layouts[6])
text_frame = slide.shapes.add_textbox(Inches(1), Inches(1), Inches(7), Inches(2)).text_frame
text_frame.text = "Account: Alice\vBalance: 100"
buffer = io.BytesIO()
presentation.save(buffer)

converter = PPTXToDocument(link_format=link_format)
output = converter.run(sources=[ByteStream(data=buffer.getvalue())])

assert output["documents"][0].content == "Account: Alice\vBalance: 100"