Documentation
¶
Overview ¶
Package pptx extracts slide and speaker-notes text from PPTX (Office Open XML) sources.
A .pptx is a ZIP archive of XML. Slide text lives in ppt/slides/slideN.xml and is carried by DrawingML text runs (<a:t>) inside paragraphs (<a:p>) — the same local element names DOCX uses, so the decode is shared in spirit with the docx extractor. This extractor unzips in memory, walks slides in presentation order, and for each slide appends its body text followed by its speaker notes (if any).
Slide order comes from ppt/presentation.xml's slide-id list resolved through ppt/_rels/presentation.xml.rels — the order the deck actually presents, which can differ from the slideN.xml filename numbers after a deck is reordered. If those parts are missing or unparseable, it falls back to numeric filename order; any slide parts not referenced by the presentation are appended after the ordered ones so no slide is silently dropped.
Notes are associated to their slide through the slide's own relationships (ppt/slides/_rels/slideN.xml.rels → a notesSlide target), so a note stays with the slide it belongs to. The result is a single text/plain artifact in the same shape as the core text extractor, with blank lines between paragraphs so the boundary-aware chunker sees structure.
Like docx, this needs no third-party dependency (stdlib archive/zip + encoding/xml) but stays a subpackage so all formats are uniformly opt-in (see docs/adr/0006-optional-adapters-as-subpackages.md):
reg.Register("application/vnd.openxmlformats-officedocument.presentationml.presentation", pptx.New())
Scope is slide body text plus speaker notes. Masters, layouts, comments, and embedded objects are not extracted; that can be added later by parsing more archive parts.
Index ¶
Constants ¶
const DefaultMaxDecompressedBytes int64 = 64 << 20 // 64 MiB
DefaultMaxDecompressedBytes caps the total uncompressed XML this extractor reads across all parts (presentation, slides, notes, relationships). The Registry bounds the *compressed* input, but a zip bomb can expand far beyond that, so the uncompressed stream needs its own ceiling. 64 MiB is far larger than any realistic deck's text parts while still bounding memory.
const MediaType content.MediaType = "application/vnd.openxmlformats-officedocument.presentationml.presentation"
MediaType is the media type this extractor handles.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Extractor ¶
type Extractor struct {
// MaxDecompressedBytes caps the total uncompressed size of the parts read,
// defending against a zip bomb whose compressed form fits under the Registry's
// input cap but expands to exhaust memory. Zero or negative means
// DefaultMaxDecompressedBytes.
MaxDecompressedBytes int64
}
Extractor extracts slide and notes text from PPTX sources. It carries only immutable configuration and is safe for concurrent use.
func (Extractor) Extract ¶
func (e Extractor) Extract(ctx context.Context, r io.Reader, parentID string) ([]content.Artifact, error)
Extract reads r as a .pptx archive and returns a single text/plain artifact derived from parentID: each slide's body text followed by its speaker notes, slides in presentation order, paragraphs separated by blank lines. It honors ctx cancellation while reading. It returns:
- extract.ErrNoContent if the deck parses cleanly but has no slide/notes text;
- an error matching extract.ErrMalformedSource if the archive is not a valid zip, contains no slides, contains unparseable XML, declares a notes slide whose target is missing, or whose parts decompress past MaxDecompressedBytes (a zip bomb).