Auditing PPTX: Structure, Semantics, and Zero Guesswork
go-pptx Tech Blog · Part 8: Read-Only Auditing — IR, Semantic Diff, and the Six-Dimensional Capability Manifest
Series: go-pptx Tech Blog (10 parts)
Baseline: v2.4.4
Keywords: read-only IR, timing IR, weighted LCS, Jaccard, opaque diff, Capability, Validate
1. Why "Read-Only" Capabilities Are Needed
Editing is not the only need. In real engineering, people often need to:
- Content extraction: extract PPT text/notes/tables and feed them to search, RAG, or review;
- Version comparison: legal contracts, before/after translation, editing workflows—want to know "what exactly changed";
- Pre-deployment capability confirmation: can this library handle my file? Which capabilities are limited?
- Structural validation: check for duplicate shape IDs, dangling relationships, and over-limit resources before release.
These operations should not modify the document, nor should they require callers to parse OOXML themselves. go-pptx's answer is:
-
Read-only IR (
go-pptx.ir/1.0): a structured JSON view; -
Semantic Diff (
go-pptx.diff/1.0): page alignment + shape-level comparison; -
Validate: structural diagnostics; -
Capability: the six-dimensional capability manifest.
They share the same core through internal/engine; the CLI and WASM do not each write their own.
2. Read-Only IR: Giving a Document a Stable JSON View
2.1 Top-level structure
{
"schemaVersion": "go-pptx.ir/1.0",
"sdkVersion": "v2.4.4",
"documentID": "...",
"core": { "title": "...", "creator": "..." },
"pages": [
{
"index": 0,
"slideID": 256,
"part": "/ppt/slides/slide1.xml",
"name": "Cover",
"shapes": [
{
"id": 2,
"name": "Title 1",
"kind": "autoShape",
"bounds": { "x": 914400, "y": 914400, "w": 6096000, "h": 914400 },
"text": "Q4 Business Analysis"
}
],
"notesText": "Hello everyone...",
"hasTiming": true,
"hidden": false
}
],
"diagnostics": []
}
2.2 Projected content
The current IR covers:
- Document metadata summary (
core.xml); - Page order,
SlideID, name, notes text, hidden state; - Top-level shapes: ID / Name / Kind / AltText / Decorative / Bounds / WorldBox;
- Charts: type and first Categories group;
- Tables: rows/columns and plain-text concatenation;
- Text boxes/auto shapes: paragraph text;
- Media Part name + ContentType (binary not embedded);
- timing IR (optional).
2.3 schemaVersion is independent of the SDK version
go-pptx.ir/1.0 has its own version cadence:
- Adding optional fields stays backward compatible;
- Deleting/renaming/changing types must bump
schemaVersion; - Callers judge compatibility by schemaVersion, not by library version number.
2.4 Read-only constraints
IR cannot be used as input for "PPTX → PPTX default overwrite save". It is used only for:
- Content extraction;
- Debugging/preview;
- Cross-format adaptation;
- The input view for semantic diff.
In the future, if "importing from IR" is needed, it must go through an explicit lossy new-creation interface, rather than "read it out and overwrite everything".
2.5 timing IR
The p:timing subtree is the core of animation/playback, with complex structure and many vendor extensions. IR projects it as:
-
PageTiming; -
TimingNode: Kind (parallel/sequence/cTn/audio/video/cmd/anim/set/opaque); - Trigger conditions (Begin/End);
- Animation target (Target);
- Unrecognized child elements are output as
OpaqueNodeand counted in diagnostics.
The principle is "do not guess, do not omit": recognized structures are structured, unrecognized ones are marked opaque.
3. Semantic Diff: Why Not Compare by Line/Byte
The differences between two PPTX files may come from:
- Text changed;
- Shape moved/scaled;
- Page order changed;
- A page deleted, a page added;
- Notes changed;
- Animation timing changed;
- Unknown extensions changed internally.
If you diff XML text directly, you get a lot of "tag order/whitespace/namespace" noise; if you crudely compare by position under "page correspondence", you will misjudge "inserting one page" as "every page after it changed".
go-pptx's approach is two-level alignment:
3.1 Page level: weighted LCS + Jaccard
The rules of pageScore(a, b):
- Both sides have non-zero and equal
SlideID→ 1.0 (strong match); - Both sides have non-zero but unequal
SlideID→ 0 (definitely different pages); - Otherwise, use the Jaccard similarity of the set of shape IDs within the page.
Thresholds:
-
matchThreshold = 0.5: treated as "two revisions of the same page" in the ordered LCS; -
orphanThreshold = 0.8: secondary pairing of leftover pages after ordered alignment (to identify moves/reorders); a higher threshold avoids mismatching "added pages" with "removed pages".
Alignment flow:
- Use weighted LCS for order-sensitive alignment;
- Do secondary matching for unpaired pages (allowing out-of-order), marking them as moved;
- Still unpaired → page added/page removed;
- Compare aligned pages one by one.
Very large documents (page count product > 1,000,000) degrade to linear alignment of "same SlideID first, the rest by position" to avoid runaway memory/time.
3.2 Within a page: pair by ShapeID
Within aligned pages:
- Pair by
ShapeID; - Compare text, geometry, type, name, alt text, table size, and chart type;
- Recursively handle child shapes within groups;
- Unrecognized/unprojected regions are marked as opaque diff, with
Part+NodePathgiven, but internal changes are not guessed.
3.3 Change types
Stable string enums, callers can branch directly:
document.core_changed
page.added / page.removed / page.moved
page.notes_changed / page.timing_changed
shape.added / shape.removed
shape.text_changed / shape.bounds_changed / shape.kind_changed
shape.name_changed / shape.alttext_changed
shape.table_size_changed / shape.chart_type_changed
opaque.diff
3.4 Report structure
{
"schemaVersion": "go-pptx.diff/1.0",
"changed": true,
"stats": {
"pagesAdded": 1,
"pagesRemoved": 0,
"pagesMoved": 0,
"pagesChanged": 2,
"textChanges": 3,
"opaqueRegions": 1
},
"entries": [
{
"kind": "shape.text_changed",
"pageIndexA": 0,
"pageIndexB": 0,
"shapeID": 2,
"part": "/ppt/slides/slide1.xml",
"nodePath": "p:sld/p:cSld/p:spTree/p:sp[1]",
"from": "Q3 Revenue",
"to": "Q4 Revenue"
}
],
"opaque": [
{
"part": "/ppt/slides/slide1.xml",
"nodePath": "...",
"reason": "Chart cache values are not in the IR (only the chart type is projected)",
"changed": true
}
]
}
3.5 Options
ir.Diff(a, b,
ir.WithIgnoreGeometry(true),
ir.WithIgnoreWhitespace(true),
ir.WithIgnoreNotes(true),
ir.WithMaxEntries(1000),
)
-
IgnoreGeometry: compare content only; -
IgnoreWhitespace: text normalization; -
IgnoreNotes: ignore notes; -
MaxEntries: limit the number of report entries; overflow is markedTruncated, but statistics continue.
4. Validate: Structural Diagnostics, Not "It Opens So It Passes"
Validate performs L0 structural validation and outputs a list of Diagnostic. Typical diagnostics:
| Diagnostic code | Severity | Trigger condition |
|---|---|---|
DRAWING_ID_DUPLICATE |
Warning |
cNvPr@id duplicated within the same slide spTree |
OPC_DANGLING_REL |
Depends on context | Relationship points to a non-existent Part |
| Other structural/resource diagnostics | Info/Warning/Error | Determined by the specific check |
Design principles:
- Diagnose by default, do not refuse to open: malformed but readable files can still be inspected;
-
Strict mode is up to the caller: refuse after reading
ValidationReport; - Do not silently discard: unknown content is preserved, and problems are presented as diagnostics.
CLI:
pptx validate deck.pptx
# Exit code 3 when the error count > 0
5. Capability: The Six-Dimensional Capability Manifest
5.1 The six dimensions
| Dimension | Current status | Description |
|---|---|---|
| Inspect | Supported | Full read-only inspection |
| Create | Partial | Supported features can be created |
| Edit | Partial | Cross-Run text, tables, media, clone, bind |
| Preserve | Supported | Byte-level fidelity (B1) |
| Render | Untested | Interface landed, implementation not yet planned |
| Play | Partial | timing read-only + audio narration attachment |
5.2 Four status levels
Supported Core scenarios have been verified in golden samples and tests
Partial A limited subset has been verified; uncovered paths explicitly error
Unsupported Declared unsupported; callers should degrade/work around it
Untested Not yet verified on real corpora (default, transparent to callers)
5.3 manifest structure
{
"schemaVersion": "go-pptx.capability/1.0",
"sdkVersion": "v2.4.4",
"dimensions": {
"inspect": { "status": "Supported", "notes": "...", "limits": [] },
"create": { "status": "Partial", "notes": "...", "limits": [] },
"edit": { "status": "Partial", "notes": "...", "limits": [] },
"preserve": { "status": "Supported", "notes": "...", "limits": [] },
"render": { "status": "Untested", "notes": "...", "limits": [] },
"play": { "status": "Partial", "notes": "...", "limits": [] }
},
"features": [
{
"id": "TEXT-02",
"dimension": "edit",
"status": "Supported",
"notes": "Cross-Run faithful replacement"
}
]
}
5.4 Why this matters
Most libraries only say "supports PPTX". But real projects need to know:
- Can it read? Can it write?
- Can it write? Can it preserve fidelity?
- Can it preserve fidelity? Can it play?
- For capabilities it cannot do, does it return an error or silently degrade?
Capability turns the answers to these questions into machine-readable JSON. Running pptx capability once before deployment is much better than discovering "this chart cannot be modified" only after going live.
6. CLI: inspect / diff / export-ir / capability / validate
# Structured inspection
pptx inspect deck.pptx > report.json
# Semantic diff
pptx diff --ignore-whitespace old.pptx new.pptx > diff.json
# Export IR
pptx export-ir --output deck.ir.json deck.pptx
# Capability manifest
pptx capability > capability.json
# Structural validation
pptx validate deck.pptx
Exit codes:
-
0success; -
1runtime error; -
2usage error; -
3capability/validation error; -
4resource limit.
7. Design Trade-offs
| Question | Choice | Reason |
|---|---|---|
| Does IR embed media | No, only Part name + type | IR is a structured view, not a package copy |
| Can IR be saved back | No | Avoids "read it out and overwrite everything" breaking fidelity |
| Page alignment | SlideID strong match + Jaccard + LCS | Distinguishes "same-page revision" from "page deleted + page added" |
| Out-of-order pages | High-threshold secondary pairing | Identifies moves, avoids mismatching additions/deletions |
| Unprojected regions | opaque diff + Part/NodePath | Traceable, but does not guess |
| Very large documents | Linear degradation alignment | Prevents runaway memory/time |
| Diagnostic strategy | Record by default, do not refuse to open | Auditing scenarios need to "read malformed files" |
| Capability status | Four levels + six dimensions | Avoids the binary "supported/unsupported" hiding limitations |
8. Summary
The core of the read-only auditing chain is "structured + traceable + no guessing":
- IR provides a stable JSON view, with the schema versioned independently;
- timing IR structures what it recognizes and marks the rest opaque;
- Diff uses page alignment + shape pairing to distinguish revision/move/add/remove;
- opaque diff gives Part/NodePath but does not fabricate internal changes;
- Capability uses six dimensions and four levels to make "what it can and cannot do" machine-readable.
The next part moves into quality engineering: how these capabilities are constrained by corpora, golden samples, coverage, fuzz, and a real-device matrix.
Series navigation: ← Part 7: Template Data Binding · Part 9: Quality Engineering →
Top comments (0)