docparser-office 0.1.0

docparser Office 后端:DOCX / XLSX / PPTX 解析(zip + quick-xml 流式)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
//! PPTX 解析:ZIP + quick-xml 流式文本提取。
//!
//! 架构:`PptxRawBackend` -> `ParseCapability`,支持 slide 排序、形状文本提取、
//! 组合形状递归、图表/表格/备注 slide。

use docparser_core::error::{DocError, Result};
use docparser_core::plugin::{ParseCapability, RawDoc, RawPage};
use quick_xml::events::Event;
use quick_xml::Reader;

use crate::parse_rels;
use std::collections::HashMap;

/// PPTX raw 后端。
pub struct PptxRawBackend;

impl ParseCapability for PptxRawBackend {
    fn id(&self) -> &str {
        "office-raw"
    }
    fn formats(&self) -> &[&str] {
        &["pptx"]
    }
    fn parse(&self, path: &str) -> Result<RawDoc> {
        let file = std::fs::File::open(path)
            .map_err(|e| DocError::corrupt(format!("cannot open {path}: {e}")))?;
        let mut zip = zip::ZipArchive::new(file)
            .map_err(|e| DocError::corrupt(format!("ZIP open failed: {e}")))?;

        // 全量缓存所有 XML 和 rels 文件,避免 per-slide 多次 ZIP 遍历
        let mut cache: HashMap<String, String> = HashMap::new();
        for i in 0..zip.len() {
            let mut f = zip
                .by_index(i)
                .map_err(|e| DocError::corrupt(format!("ZIP entry error at index {i}: {e}")))?;
            // zip 9:条目名改为 Result<Cow<str>, ZipError>(非法 UTF-8 名不再静默)
            let name = f
                .name()
                .map_err(|e| DocError::corrupt(format!("ZIP entry name error at index {i}: {e}")))?
                .to_string();
            if name.ends_with(".xml") || name.ends_with(".rels") {
                let mut buf = Vec::new();
                std::io::Read::read_to_end(&mut f, &mut buf)
                    .map_err(|e| DocError::corrupt(format!("读取 {name} 失败: {e}")))?;
                let s = String::from_utf8(buf)
                    .map_err(|e| DocError::corrupt(format!("{name} 不是 UTF-8: {e}")))?;
                cache.insert(name, s);
            }
        }

        // 读取 slide 列表
        let pres_xml = cache
            .get("ppt/presentation.xml")
            .ok_or_else(|| DocError::corrupt("missing ppt/presentation.xml"))?;
        let slide_rids = parse_slide_list(pres_xml)?;

        // 读取 rels 获取 slide 路径
        let pres_rels = cache
            .get("ppt/_rels/presentation.xml.rels")
            .map(|s| s.as_str())
            .unwrap_or("");
        let rels_map = parse_rels(pres_rels);

        // 获取所有的 slide 文件路径(按文档顺序)
        let slide_paths: Vec<String> = slide_rids
            .iter()
            .filter_map(|rid| {
                let target = rels_map.get(rid)?;
                // target 可能是 "slides/slide1.xml" 或 "./slides/slide1.xml"
                let cleaned = target.trim_start_matches("./");
                Some(format!("ppt/{}", cleaned))
            })
            .collect();

        if slide_paths.is_empty() {
            return Err(DocError::corrupt("no slides found in presentation.xml"));
        }

        // 解析每个 slide
        let mut pages = Vec::new();
        for (idx, slide_path) in slide_paths.iter().enumerate() {
            let xml = cache.get(slide_path).cloned().unwrap_or_default();

            // 提取 slide 文本(带位置)和 chart 图形框位置
            let (mut pos_items, chart_positions) = extract_slide_items(&xml)?;

            // 从文件路径 "ppt/slides/slideN.xml" 提取 N(用于备注/关系映射)
            let slide_num: usize = slide_path
                .trim_start_matches("ppt/slides/slide")
                .trim_end_matches(".xml")
                .parse()
                .unwrap_or(idx + 1);

            // 1. 演讲者备注(跳过 slide number 等纯数字占位符,放在最后)
            let notes_path = format!("ppt/notesSlides/notesSlide{}.xml", slide_num);
            if let Some(notes_xml) = cache.get(&notes_path) {
                if let Ok(notes_texts) = extract_slide_texts(notes_xml) {
                    for t in notes_texts {
                        let trimmed = t.trim();
                        if !trimmed.is_empty() && !trimmed.chars().all(|c| c.is_ascii_digit()) {
                            pos_items.push((i64::MAX, i64::MAX, trimmed.to_string()));
                        }
                    }
                }
            }

            // 2. 图表文本(带 chart 图形框的位置)
            let rels_path = format!("ppt/slides/_rels/slide{}.xml.rels", slide_num);
            if let Some(rels_xml) = cache.get(&rels_path) {
                let chart_targets = find_chart_targets(rels_xml);
                // 配对 chart 文本和位置
                for (ci, target) in chart_targets.iter().enumerate() {
                    let chart_path = resolve_rels_target(slide_path, target);
                    if let Some(chart_xml) = cache.get(&chart_path) {
                        let (c_y, c_x) = chart_positions.get(ci).copied().unwrap_or((0, 0));
                        if let Ok(chart_texts) = extract_chart_texts(chart_xml) {
                            for t in chart_texts {
                                if !t.trim().is_empty() {
                                    pos_items.push((c_y, c_x, t));
                                }
                            }
                        }
                    }
                }
            }

            // 按位置 (y, x) 排序,备注在最后
            pos_items.sort_by(|a, b| a.0.cmp(&b.0).then(a.1.cmp(&b.1)));

            let items: Vec<docparser_core::plugin::RawTextItem> = pos_items
                .into_iter()
                .map(|(_, _, text)| docparser_core::plugin::RawTextItem { text, bbox: None })
                .collect();

            if !items.is_empty() {
                pages.push(RawPage {
                    name: Some(format!("Slide {}", idx + 1)),
                    items,
                    ..Default::default()
                });
            }
        }

        Ok(RawDoc {
            pages,
            ..Default::default()
        })
    }
}

/// 解析 `<sldIdLst>` 获取 slide 的 r:id 列表(保持文档顺序)。
fn parse_slide_list(xml: &str) -> Result<Vec<String>> {
    let mut reader = Reader::from_str(xml);
    // 不裁剪文本:空白由消费者 trim(实体两侧空格需保留,见 GeneralRef 分支)
    let mut buf = Vec::new();
    let mut rids = Vec::new();

    loop {
        match reader.read_event_into(&mut buf) {
            Ok(Event::Empty(ref e)) | Ok(Event::Start(ref e)) => {
                if e.name().local_name().as_ref() == crate::tags::P_SLDID {
                    for attr in e.attributes().filter_map(|a| a.ok()) {
                        // 属性按完整 QName 比较:只认 r:id,`sldId` 自己的裸 id 不算关系 id
                        if attr.key.as_ref() == "r:id" {
                            rids.push(attr.value.to_string());
                        }
                    }
                }
            }
            Ok(Event::End(ref e)) => {
                if e.name().local_name().as_ref() == "presentation" {
                    break;
                }
            }
            Ok(Event::Eof) => break,
            Err(e) => return Err(DocError::corrupt(format!("presentation parse error: {e}"))),
            _ => {}
        }
        buf.clear();
    }
    Ok(rids)
}

/// `(y, x, text)` 文本项 + chart 图形框位置。
type SlideItems = (Vec<(i64, i64, String)>, Vec<(i64, i64)>);

/// 提取 slide 文本(带形状位置)和 chart 图形框的位置。
///
/// 返回 `(text_items, chart_positions)`:
/// - `text_items`:`(y, x, text)`,按形状在 XML 中出现的顺序
/// - `chart_positions`:`(y, x)`,对应 chart rel 顺序的图形框位置
fn extract_slide_items(xml: &str) -> Result<SlideItems> {
    let mut reader = Reader::from_str(xml);
    // 不裁剪文本:空白由消费者 trim(实体两侧空格需保留,见 GeneralRef 分支)
    let mut buf = Vec::new();
    let mut items = Vec::new();
    let mut chart_positions = Vec::new();

    let mut shape_depth: u32 = 0;
    let mut cur_y: i64 = 0;
    let mut cur_x: i64 = 0;
    let mut in_t = false;
    let mut text_buf = String::new();
    let mut shape_texts: Vec<String> = Vec::new();
    let mut is_chart_frame = false;
    // 表格结构追踪
    let mut in_tbl = false;
    let mut in_tr = false;
    let mut in_tc = false;
    let mut cell_text = String::new();
    let mut row_cells: Vec<String> = Vec::new();
    let mut table_rows: Vec<String> = Vec::new();

    loop {
        match reader.read_event_into(&mut buf) {
            Ok(Event::Start(ref e)) => {
                let name = e.name().local_name().as_ref().to_string();

                if matches!(
                    name.as_str(),
                    crate::tags::P_SP
                        | crate::tags::P_GFRAME
                        | crate::tags::P_GRPSP
                        | crate::tags::P_CXNSP
                ) {
                    if shape_depth == 0 {
                        cur_x = 0;
                        cur_y = 0;
                        shape_texts.clear();
                        is_chart_frame = name == crate::tags::P_GFRAME;
                    }
                    shape_depth += 1;
                }

                if shape_depth > 0 {
                    if name == crate::tags::A_OFF || name == crate::tags::A_POS {
                        for attr in e.attributes().filter_map(|a| a.ok()) {
                            match attr.key.as_ref() {
                                "y" => cur_y = attr.value.parse().unwrap_or(0),
                                "x" => cur_x = attr.value.parse().unwrap_or(0),
                                _ => {}
                            }
                        }
                    }

                    if name == crate::tags::A_T {
                        in_t = true;
                        text_buf.clear();
                    } else if name == crate::tags::A_BR
                        && (!text_buf.is_empty() || !shape_texts.is_empty())
                    {
                        shape_texts.push(std::mem::take(&mut text_buf));
                    } else if name == crate::tags::A_TBL {
                        in_tbl = true;
                        table_rows.clear();
                    } else if name == crate::tags::A_TR {
                        in_tr = true;
                        row_cells.clear();
                    } else if name == crate::tags::A_TC {
                        in_tc = true;
                        cell_text.clear();
                    }
                }
            }
            Ok(Event::Empty(ref e)) => {
                let name = e.name().local_name().as_ref().to_string();
                if shape_depth > 0 {
                    if name == crate::tags::A_OFF || name == crate::tags::A_POS {
                        for attr in e.attributes().filter_map(|a| a.ok()) {
                            match attr.key.as_ref() {
                                "y" => cur_y = attr.value.parse().unwrap_or(0),
                                "x" => cur_x = attr.value.parse().unwrap_or(0),
                                _ => {}
                            }
                        }
                    }
                    if name == crate::tags::A_T {
                        in_t = true;
                        text_buf.clear();
                    } else if name == crate::tags::A_BR
                        && (!text_buf.is_empty() || !shape_texts.is_empty())
                    {
                        shape_texts.push(std::mem::take(&mut text_buf));
                    }
                }
            }
            Ok(Event::End(ref e)) => {
                let name = e.name().local_name().as_ref().to_string();
                if shape_depth > 0 {
                    if name == crate::tags::A_T {
                        in_t = false;
                        let trimmed = text_buf.trim().to_string();
                        if !trimmed.is_empty() {
                            if in_tc {
                                // 表格单元格内:accumulate for row joining
                                if !cell_text.is_empty() {
                                    cell_text.push('\n');
                                }
                                cell_text.push_str(&trimmed);
                            } else {
                                shape_texts.push(trimmed);
                            }
                        }
                        text_buf.clear();
                    } else if name == crate::tags::A_TC {
                        if in_tc {
                            row_cells.push(std::mem::take(&mut cell_text));
                            in_tc = false;
                        }
                    } else if name == crate::tags::A_TR {
                        if in_tr {
                            let row_str = row_cells.join(",");
                            table_rows.push(row_str);
                            row_cells.clear();
                            in_tr = false;
                        }
                    } else if name == crate::tags::A_TBL {
                        in_tbl = false;
                    }

                    if matches!(
                        name.as_str(),
                        crate::tags::P_SP
                            | crate::tags::P_GFRAME
                            | crate::tags::P_GRPSP
                            | crate::tags::P_CXNSP
                    ) {
                        shape_depth -= 1;
                        if shape_depth == 0 {
                            // 只有非表格的 graphicFrame 才计入 chart_positions
                            if is_chart_frame && !in_tbl {
                                chart_positions.push((cur_y, cur_x));
                            }
                            if !table_rows.is_empty() {
                                // 表格行输出
                                for t in &table_rows {
                                    if !t.is_empty() {
                                        items.push((cur_y, cur_x, t.clone()));
                                    }
                                }
                                table_rows.clear();
                            } else {
                                for t in &shape_texts {
                                    if !t.is_empty() {
                                        items.push((cur_y, cur_x, t.clone()));
                                    }
                                }
                            }
                            shape_texts.clear();
                        }
                    }
                }
            }
            Ok(Event::Text(ref e)) => {
                if in_t {
                    // quick-xml 0.38+:Text 已是解码后的字符串,实体需显式 unescape
                    let raw = e.xml10_content();
                    if let Ok(t) = quick_xml::escape::unescape(&raw) {
                        text_buf.push_str(&t);
                    }
                }
            }
            Ok(Event::GeneralRef(ref e)) => {
                if in_t {
                    crate::push_general_ref(&mut text_buf, e);
                }
            }
            Ok(Event::CData(ref e)) => {
                if in_t {
                    text_buf.push_str(e.as_ref());
                }
            }
            Ok(Event::Eof) => break,
            Err(e) => return Err(DocError::corrupt(format!("slide parse error: {e}"))),
            _ => {}
        }
        buf.clear();
    }

    Ok((items, chart_positions))
}

/// 提取备注 slide 中的纯文本(用于 `extract_slide_items` 之外的场景,如 notes)。
fn extract_slide_texts(xml: &str) -> Result<Vec<String>> {
    let mut reader = Reader::from_str(xml);
    // 不裁剪文本:空白由消费者 trim(实体两侧空格需保留,见 GeneralRef 分支)
    let mut buf = Vec::new();
    let mut texts = Vec::new();
    let mut in_t = false;
    let mut text_buf = String::new();

    loop {
        match reader.read_event_into(&mut buf) {
            Ok(Event::Start(ref e)) => {
                let name = e.name().local_name().as_ref().to_string();
                if name == crate::tags::A_T {
                    in_t = true;
                    text_buf.clear();
                } else if name == crate::tags::A_BR && (!text_buf.is_empty() || !texts.is_empty()) {
                    // 换行符
                    texts.push(std::mem::take(&mut text_buf));
                }
            }
            Ok(Event::Empty(ref e)) => {
                let name = e.name().local_name().as_ref().to_string();
                if name == crate::tags::A_T {
                    in_t = true;
                    text_buf.clear();
                } else if name == crate::tags::A_BR && (!text_buf.is_empty() || !texts.is_empty()) {
                    texts.push(std::mem::take(&mut text_buf));
                }
            }
            Ok(Event::End(ref e)) => {
                let name = e.name().local_name().as_ref().to_string();
                if name == crate::tags::A_T {
                    in_t = false;
                    let trimmed = text_buf.trim().to_string();
                    if !trimmed.is_empty() {
                        texts.push(trimmed);
                    }
                    text_buf.clear();
                }
            }
            Ok(Event::Text(ref e)) => {
                if in_t {
                    // quick-xml 0.38+:Text 已是解码后的字符串,实体需显式 unescape
                    let raw = e.xml10_content();
                    if let Ok(t) = quick_xml::escape::unescape(&raw) {
                        text_buf.push_str(&t);
                    }
                }
            }
            Ok(Event::GeneralRef(ref e)) => {
                if in_t {
                    crate::push_general_ref(&mut text_buf, e);
                }
            }
            Ok(Event::CData(ref e)) => {
                if in_t {
                    text_buf.push_str(e.as_ref());
                }
            }
            Ok(Event::Eof) => break,
            Err(e) => return Err(DocError::corrupt(format!("slide parse error: {e}"))),
            _ => {}
        }
        buf.clear();
    }
    Ok(texts)
}

/// 从 slide rels XML 中找出所有 chart 引用的 Target 路径。
fn find_chart_targets(rels_xml: &str) -> Vec<String> {
    use quick_xml::events::Event;
    use quick_xml::Reader;

    let mut reader = Reader::from_str(rels_xml);
    // 不裁剪文本:空白由消费者 trim(实体两侧空格需保留,见 GeneralRef 分支)
    let mut buf = Vec::new();
    let mut targets = Vec::new();
    let chart_type = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart";

    loop {
        match reader.read_event_into(&mut buf) {
            Ok(Event::Empty(ref e)) | Ok(Event::Start(ref e)) => {
                if e.name().local_name().as_ref() == "Relationship" {
                    let mut target = None;
                    let mut type_val = None;
                    for attr in e.attributes().filter_map(|a| a.ok()) {
                        match attr.key.as_ref() {
                            "Type" => type_val = Some(attr.value.to_string()),
                            "Target" => target = Some(attr.value.to_string()),
                            _ => {}
                        }
                    }
                    if type_val.as_deref() == Some(chart_type) {
                        if let Some(t) = target {
                            targets.push(t);
                        }
                    }
                }
            }
            Ok(Event::Eof) => break,
            _ => {}
        }
        buf.clear();
    }
    targets
}

/// 将 rels 中相对于源文件的 Target 路径解析为 ZIP 中的绝对路径。
///
/// source_path: "ppt/slides/slide1.xml"
/// target:     "../charts/chart1.xml"
/// result:     "ppt/charts/chart1.xml"
fn resolve_rels_target(source_path: &str, target: &str) -> String {
    let source_dir = source_path
        .rfind('/')
        .map(|i| &source_path[..i])
        .unwrap_or("");
    let mut result = source_dir.to_string();
    let mut remaining = target;
    while remaining.starts_with("../") {
        if let Some(idx) = result.rfind('/') {
            result = result[..idx].to_string();
        } else {
            result.clear();
        }
        remaining = &remaining[3..];
    }
    if result.is_empty() {
        remaining.to_string()
    } else {
        format!("{}/{}", result, remaining)
    }
}

/// 从 chart XML 中提取文本。
///
/// 提取 `<a:t>`(富文本标题/标签)和 `<c:tx>` 内 `<c:v>`(纯文本数据标签)。
/// 图表 title 和 data label 的文本通常在这两种形式中,而分类/序列数据值
/// 不在 `<c:tx>` 内,不会被提取。
fn extract_chart_texts(xml: &str) -> Result<Vec<String>> {
    let mut reader = Reader::from_str(xml);
    // 不裁剪文本:空白由消费者 trim(实体两侧空格需保留,见 GeneralRef 分支)
    let mut buf = Vec::new();
    let mut texts = Vec::new();
    let mut in_t = false;
    let mut in_tx = false;
    let mut in_tx_v = false;
    let mut text_buf = String::new();

    loop {
        match reader.read_event_into(&mut buf) {
            Ok(Event::Start(ref e)) => {
                let name = e.name().local_name().as_ref().to_string();
                if name == crate::tags::C_TX {
                    in_tx = true;
                } else if name == crate::tags::C_V && in_tx {
                    in_tx_v = true;
                    text_buf.clear();
                } else if name == crate::tags::A_T {
                    in_t = true;
                    text_buf.clear();
                }
            }
            Ok(Event::End(ref e)) => {
                let name = e.name().local_name().as_ref().to_string();
                if name == crate::tags::C_TX {
                    in_tx = false;
                } else if name == crate::tags::C_V && in_tx_v {
                    in_tx_v = false;
                    let t = text_buf.trim().to_string();
                    if !t.is_empty() {
                        texts.push(t);
                    }
                    text_buf.clear();
                } else if name == crate::tags::A_T {
                    in_t = false;
                    let t = text_buf.trim().to_string();
                    if !t.is_empty() {
                        texts.push(t);
                    }
                    text_buf.clear();
                }
            }
            Ok(Event::Text(ref e)) => {
                if in_t || in_tx_v {
                    let raw = e.xml10_content();
                    if let Ok(t) = quick_xml::escape::unescape(&raw) {
                        text_buf.push_str(&t);
                    }
                }
            }
            Ok(Event::GeneralRef(ref e)) => {
                if in_t || in_tx_v {
                    crate::push_general_ref(&mut text_buf, e);
                }
            }
            Ok(Event::CData(ref e)) => {
                if in_t || in_tx_v {
                    text_buf.push_str(e.as_ref());
                }
            }
            Ok(Event::Eof) => break,
            Err(_) => break,
            _ => {}
        }
        buf.clear();
    }
    Ok(texts)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_slide_list() {
        let xml = concat!(
            r#"<p:presentation xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" "#,
            r#"xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">"#,
            r#"  <p:sldIdLst>"#,
            r#"    <p:sldId id="256" r:id="rId1"/>"#,
            r#"    <p:sldId id="257" r:id="rId2"/>"#,
            r#"  </p:sldIdLst>"#,
            r#"</p:presentation>"#
        );
        let rids = parse_slide_list(xml).unwrap();
        assert_eq!(rids, vec!["rId1", "rId2"]);
    }

    #[test]
    fn test_slide_text() {
        let xml = concat!(
            r#"<p:sld xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" "#,
            r#"xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">"#,
            r#"  <p:spTree>"#,
            r#"    <p:sp>"#,
            r#"      <p:nvSpPr><p:cNvPr id="1"/><p:cNvSpPr/><p:nvPr/></p:nvSpPr>"#,
            r#"      <p:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="100" cy="50"/></a:xfrm></p:spPr>"#,
            r#"      <p:txBody>"#,
            r#"        <a:p>"#,
            r#"          <a:r>"#,
            r#"            <a:t>Hello World</a:t>"#,
            r#"          </a:r>"#,
            r#"        </a:p>"#,
            r#"      </p:txBody>"#,
            r#"    </p:sp>"#,
            r#"  </p:spTree>"#,
            r#"</p:sld>"#
        );
        let (items, chart_pos) = extract_slide_items(xml).unwrap();
        assert!(chart_pos.is_empty());
        assert!(items.iter().any(|(_, _, t)| t == "Hello World"));
    }
}