Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

refactor(pptx): simplify buildPPTXJSONSections + drop Python-compat wording (Follow-ups 1+2 of #19076) (#19098)

Harsh Kashyapbe38e1eaf1f1
diff --git a/internal/parser/parser/pptx_ir.go b/internal/parser/parser/pptx_ir.go
index 3028cd95f6..cfe412646e 100644
--- a/internal/parser/parser/pptx_ir.go
+++ b/internal/parser/parser/pptx_ir.go
@@ -43,13 +43,13 @@ func buildPPTXJSONSections(irJSON string) ([]map[string]any, error) {
for i, sec := range ir.Sections {
var lines []string
for _, el := range sec.Elements {
- // Trim each line and drop blank ones: consecutive hard line
- // breaks collapse to a single newline, so exactly one newline
- // survives between two non-empty lines.
- for _, line := range strings.Split(docxElementText(el), "\n") {
- if line = strings.TrimSpace(line); line != "" {
- lines = append(lines, line)
- }
+ // Each element's full text (paragraphs, table cells, list
+ // items, etc.) becomes a single value; the shared IR walker
+ // already inserts newlines between rows/items, so internal
+ // newlines are preserved as-is. Only the element-level split
+ // is collapsed (one element → one value or none if empty).
+ if text := strings.TrimSpace(docxElementText(el)); text != "" {
+ lines = append(lines, text)
}
}
items = append(items, map[string]any{
diff --git a/internal/parser/parser/pptx_ir_test.go b/internal/parser/parser/pptx_ir_test.go
index c9881e4422..0444fa2569 100644
--- a/internal/parser/parser/pptx_ir_test.go
+++ b/internal/parser/parser/pptx_ir_test.go
@@ -69,11 +69,13 @@ func TestBuildPPTXJSONSections(t *testing.T) {
wantTexts: []string{"before\nafter"},
},
{
- // Regression: two consecutive breaks must collapse to exactly
- // one newline - not zero, and not a preserved blank line. Blank
- // lines are dropped, keeping one newline between two non-empty
- // lines.
- name: "consecutive hard line breaks collapse to one newline",
+ // Internal newlines emitted by the shared IR walker (e.g. between
+ // table rows or list items) are preserved as-is. The element-level
+ // split (one element -> one value or none if empty) is the only
+ // collapse applied at this layer; per-line collapse across
+ // elements happens only at element boundaries, where blank
+ // elements are dropped.
+ name: "consecutive line breaks inside one element stay as newlines",
irJSON: `{"sections":[{"elements":[
{"type":"paragraph","content":[
{"type":"text","text":"before"},
@@ -82,6 +84,18 @@ func TestBuildPPTXJSONSections(t *testing.T) {
{"type":"text","text":"after"}
]}
]}]}`,
+ wantTexts: []string{"before\n\nafter"},
+ },
+ {
+ // Element-level collapse: a blank element between two text
+ // elements is dropped, leaving a single newline between the
+ // non-empty element values.
+ name: "blank element between two text elements is dropped",
+ irJSON: `{"sections":[{"elements":[
+ {"type":"paragraph","content":[{"type":"text","text":"before"}]},
+ {"type":"paragraph","content":[]},
+ {"type":"paragraph","content":[{"type":"text","text":"after"}]}
+ ]}]}`,
wantTexts: []string{"before\nafter"},
},
{
diff --git a/internal/parser/parser/pptx_parser.go b/internal/parser/parser/pptx_parser.go
index f916ab4754..149567a29d 100644
--- a/internal/parser/parser/pptx_parser.go
+++ b/internal/parser/parser/pptx_parser.go
@@ -86,8 +86,8 @@ func (p *PPTXParser) ConfigureFromSetup(setup map[string]any) {
}
// ParseWithResult emits one JSON item per slide with the slide's
-// plain text. Mirrors the python parser.py:slides branch which
-// forces output_format="json" for the slide family.
+// plain text. Forces OutputFormat to "json" and emits one JSON item
+// per slide section.
func (p *PPTXParser) ParseWithResult(ctx context.Context, filename string, data []byte) ParseResult {
// p == nil guard: the struct is embedded by value in PPTParser and
// always created via NewPPTXParser or the "ppt"-format constructor in