Skip to content

feat: render inline article images as markdown#32

Closed
alextuan1024 wants to merge 5 commits intopublic-clis:mainfrom
alextuan1024:feat/article-inline-images
Closed

feat: render inline article images as markdown#32
alextuan1024 wants to merge 5 commits intopublic-clis:mainfrom
alextuan1024:feat/article-inline-images

Conversation

@alextuan1024
Copy link
Copy Markdown
Contributor

@alextuan1024 alextuan1024 commented Mar 17, 2026

Summary

  • render Draft.js atomic image blocks in twitter article output as Markdown images
  • preserve current article text rendering for non-media blocks
  • add regression coverage for dict-style and list-style article entityMap payloads

What changed

twitter article already converts article Draft.js blocks into Markdown, but it currently skips atomic blocks 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:

![caption](original image url)

It now supports both observed response shapes:

  • dict-style content_state.entityMap
  • list-style content_state.entityMap entries 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:

Intro

Outro

After:

Intro

![A cat](https://pbs.twimg.com/media/cat.jpg)

Outro

Validation

  • uv run --extra dev pytest -q tests/test_client.py tests/test_cli.py tests/test_serialization.py
  • uv run --extra dev ruff check twitter_cli/parser.py tests/test_client.py

Test plan

Unit / regression:

  • dict-style entityMap with inline original_url renders Markdown image
  • list-style entityMap with mediaId resolved through article.media_entities renders Markdown image
  • existing article CLI / serialization tests still pass

Manual smoke tests with real articles:

  • twitter article 'https://x.com/odyseus0z/status/2030416758138634583' --markdown
  • twitter article 'https://x.com/elvissun/status/2025920521871716562' --markdown

Notes

  • this is intentionally scoped to inline article images only
  • it keeps the existing twitter article data model unchanged and only improves Markdown extraction

@alextuan1024 alextuan1024 marked this pull request as draft March 17, 2026 07:49
@alextuan1024 alextuan1024 reopened this Mar 17, 2026
@alextuan1024 alextuan1024 reopened this Mar 17, 2026
@alextuan1024 alextuan1024 marked this pull request as ready for review March 17, 2026 08:36
@alextuan1024
Copy link
Copy Markdown
Contributor Author

Dear @jackwener,
Lemme know if you skipped images on purpose.
In that case, feel free to close this PR.

@jackwener
Copy link
Copy Markdown
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.

@jackwener jackwener closed this Mar 17, 2026
@alextuan1024
Copy link
Copy Markdown
Contributor Author

Sure. Sounds great to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants