feat: render inline article images as markdown#32
Closed
alextuan1024 wants to merge 5 commits intopublic-clis:mainfrom
Closed
feat: render inline article images as markdown#32alextuan1024 wants to merge 5 commits intopublic-clis:mainfrom
alextuan1024 wants to merge 5 commits intopublic-clis:mainfrom
Conversation
Contributor
Author
|
Dear @jackwener, |
Collaborator
|
Thanks again for the contribution. We cherry-picked the article inline image work into a new branch and finished the integration there so we can keep the recent atomic markdown fix from #37 intact as well. The follow-up PR is #38, and we also kept co-author credit for your work. To avoid duplicate review threads, we’re going to close this PR and continue from #38. |
Contributor
Author
|
Sure. Sounds great to me! |
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
atomicimage blocks intwitter articleoutput as Markdown imagesentityMappayloadsWhat changed
twitter articlealready converts article Draft.js blocks into Markdown, but it currently skipsatomicblocks entirely. Those blocks can contain inline image entities, so article exports lose embedded pictures.This patch adds best-effort extraction for article image entities and renders them as:
It now supports both observed response shapes:
content_state.entityMapcontent_state.entityMapentries of the form{ key, value }It also resolves image URLs both from inline entity data and from article-level media objects when the inline entity only carries a
mediaId.Example
Before:
After:
Validation
uv run --extra dev pytest -q tests/test_client.py tests/test_cli.py tests/test_serialization.pyuv run --extra dev ruff check twitter_cli/parser.py tests/test_client.pyTest plan
Unit / regression:
entityMapwith inlineoriginal_urlrenders Markdown imageentityMapwithmediaIdresolved througharticle.media_entitiesrenders Markdown imageManual smoke tests with real articles:
twitter article 'https://x.com/odyseus0z/status/2030416758138634583' --markdowntwitter article 'https://x.com/elvissun/status/2025920521871716562' --markdownNotes
twitter articledata model unchanged and only improves Markdown extraction