Skip to content

fix: preserve inline hyperlinks in article markdown#44

Merged
jackwener merged 3 commits intopublic-clis:mainfrom
alextuan1024:fix/article-inline-hyperlinks
Mar 21, 2026
Merged

fix: preserve inline hyperlinks in article markdown#44
jackwener merged 3 commits intopublic-clis:mainfrom
alextuan1024:fix/article-inline-hyperlinks

Conversation

@alextuan1024
Copy link
Copy Markdown
Contributor

@alextuan1024 alextuan1024 commented Mar 21, 2026

Summary

  • preserve inline LINK entities when parsing Twitter/X article Draft.js blocks
  • render linked article text as Markdown links instead of dropping the hyperlink target
  • add parser tests for inline link rendering and article-level hyperlink preservation

Problem

twitter article --markdown currently keeps article text, images, and embedded markdown blocks, but it drops inline hyperlinks carried in Draft.js entityRanges / entityMap.

That means linked phrases such as reading our docs or Skill Creator are emitted as plain text, so the article loses important context and references when exported.

Fix

Add _render_article_text_block() in twitter_cli/parser.py to:

  • inspect inline entityRanges
  • resolve LINK entities from the normalized entityMap
  • replace linked spans with Markdown links like [label](url)
  • keep existing article formatting behavior for headers, lists, blockquotes, code blocks, images, and atomic markdown blocks

Test plan

Automated

  • pytest -q tests/test_client.py tests/test_cli.py tests/test_serialization.py
    • Result: 121 passed in 5.89s
  • Regression suite: pytest -q
    • Result: 220 passed, 6 deselected in 4.04s

Manual

  • Installed the patched package in a local virtualenv and ran:
    • twitter article https://x.com/trq212/status/2033949937936085378 --markdown
  • Verified the exported Markdown now preserves inline hyperlinks from the article, including:
    • [reading our docs](https://code.claude.com/docs/en/skills)
    • [new Skilljar on Agent Skills](https://anthropic.skilljar.com/introduction-to-agent-skills)
    • [Skill Creator](https://claude.com/blog/improving-skill-creator-test-measure-and-refine-agent-skills)
    • [frontend design skill](https://github.com/anthropics/skills/blob/main/skills/frontend-design/SKILL.md)
    • [documentation](https://code.claude.com/docs/en/plugin-marketplaces)
    • [example code here](https://gist.github.com/ThariqS/24defad423d701746e23dc19aace4de5)

Notes

The article used for validation was:

@alextuan1024 alextuan1024 marked this pull request as ready for review March 21, 2026 06:10
@alextuan1024
Copy link
Copy Markdown
Contributor Author

@jackwener
Lemme know if you have different thoughts on this!

…entheses in URLs

- Early return when no entityRanges (skip unnecessary processing)
- Escape [ and ] in link labels to prevent nested bracket issues
- Encode ) in URLs as %29 to prevent malformed markdown links (e.g. Wikipedia)
- Add 3 new test cases for the above edge cases
@jackwener jackwener merged commit e3545ab into public-clis:main Mar 21, 2026
@alextuan1024 alextuan1024 deleted the fix/article-inline-hyperlinks branch March 21, 2026 10:28
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