feat(io): implement Apple Pages IWA import with heading structure#46
Merged
Conversation
Route A now correctly uses keynote-parser's real API (IWAFile + zip_file_reader) instead of the non-existent load_presentation(). Key fixes: - Patch ID_NAME_MAP at runtime to skip Pages-specific message types (e.g. type 10000 = WP.DocumentArchive) that keynote-parser doesn't know — these were crashing the entire parse before any text was read - Join the repeated-string `text` field (list) from MessageToDict output - Follow super.parent reference chain to resolve variation style names (Pages stores base styles with super.name; variations only carry super.parent pointing to the base) Tested against a real .pages document — full text + H2/H3/H4 heading hierarchy extracted correctly via pure Python, no LibreOffice needed. Also fixes markitdown version pin (>=0.3.0 → >=0.1.0); latest release is 0.1.6 and the old constraint blocked installation entirely. Closes #38 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Author
There was a problem hiding this comment.
Pull request overview
This PR adds a pure-Python Apple Pages (.pages) importer that parses iWork Archive (.iwa) content via keynote-parser to extract text and derive Markdown heading structure, with a LibreOffice + MarkItDown fallback path. It also adjusts the optional dependency pin so the Pages import extra can be installed.
Changes:
- Reworks
.pagesRoute A import to usekeynote-parser’sIWAFile+zip_file_reader, including a fallback-safeID_NAME_MAPwrapper for unknown Pages protobuf types. - Adds paragraph-style → Markdown heading prefixing by resolving paragraph style names (including following
super.parentchains). - Fixes the
markitdownoptional dependency constraint to a valid released version range.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
quill/io/pages.py |
Implements IWA parsing path, patches unknown proto types handling, and applies paragraph style-based heading prefixes; keeps LibreOffice fallback. |
pyproject.toml |
Updates pages optional dependency pin for markitdown[all] to allow installation. |
Comment on lines
+145
to
+148
| storages = [s for s in all_storage if s.get("inDocument") or s.get("in_document")] | ||
| if not storages: | ||
| storages = [s for s in all_storage if s.get("text", "").strip()] | ||
|
|
Comment on lines
3
to
5
| import subprocess | ||
| import tempfile | ||
| from pathlib import Path |
Comment on lines
+73
to
+89
| def _patched_id_name_map(): | ||
| """Return a wrapper around keynote-parser's ID_NAME_MAP that never raises KeyError.""" | ||
| import keynote_parser.codec as _codec | ||
|
|
||
| class _FallbackMap(dict): | ||
| def __missing__(self, type_id: int): | ||
| class _Factory: | ||
| _tid = type_id | ||
|
|
||
| @classmethod | ||
| def FromString(cls, data: bytes) -> "_UnknownIWAMessage": | ||
| return _UnknownIWAMessage(cls._tid, data) | ||
|
|
||
| return _Factory | ||
|
|
||
| return _FallbackMap(_codec.ID_NAME_MAP) | ||
|
|
| return _FallbackMap(_codec.ID_NAME_MAP) | ||
|
|
||
|
|
||
| def _parse_iwa_bundle(path: Path, zip_file_reader) -> dict[str, list[dict]]: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
quill/io/pages.pyto use keynote-parser's real API (IWAFile+zip_file_reader) — the previous implementation called a non-existentload_presentation()function and would always fall through to the error messageID_NAME_MAPat runtime to skip Pages-specific protobuf message types (e.g. type 10000 =WP.DocumentArchive) that keynote-parser doesn't ship definitions for — previously these crashed the entire parse before any text was reachedtextfield handling:MessageToDictreturns it as a list (repeated protobuf string), not a plain stringsuper.parentreference chain to resolve paragraph style names — Pages stores base styles withsuper.namedirectly, but variation styles only carrysuper.parentpointing back to the basemarkitdownversion pin inpyproject.toml(>=0.3.0→>=0.1.0); the latest release is 0.1.6 and the old constraint blocked installation entirelyResult
Opening a
.pagesfile now produces structured Markdown with real heading levels (H2 Articles → H3 Sections → H4 Subsections), extracted via pure Python with no LibreOffice required. Tested against a real multi-section ACBO constitution document.Test plan
python3 -m pytest tests/unit/io/test_structured.py -q— all 17 tests pass.pagesfile viapython3 -m quill yourfile.pages— document loads with heading outline intactCloses #38
🤖 Generated with Claude Code