Skip to content

fix(table): keep link addresses in table copy and download - #786

Open
mangeshraut712 wants to merge 4 commits into
vercel:mainfrom
mangeshraut712:fix/table-export-links
Open

mangeshraut712 wants to merge 4 commits into
vercel:mainfrom
mangeshraut712:fix/table-export-links

Conversation

@mangeshraut712

Copy link
Copy Markdown

Fixes #784.

Summary

When a table is copied or downloaded from its controls, links lose their address and only the link text is kept. extractTableDataFromElement reads each cell's text nodes, so an <a href> contributes its text and drops the href.

This PR serialises a link in a cell as [text](href), the same way images are already exported as ![alt](src):

  • The link text is escaped like any other cell text. An image inside the link stays Markdown, so [![logo](…)](…) round-trips.
  • The address is encoded with the same rules as image sources, so (, ), | and spaces can't end the link early.
  • The link's span is recorded in the same side table as images, so tableDataToMarkdown leaves it unescaped and TableData keeps its shape.
  • Link safety is on by default, and then a link renders as a <button> with no href. The button now carries the address in data-href, so these links are exported too. This was the case in the issue's repro with link safety on.
  • Two kinds of link stay plain text, as before:
    • A GFM autolink, whose text is already its address (https://…, www.…, or an email).
    • A link that is still streaming in (streamdown:incomplete-link).
      This keeps the existing bare-link round-trip tests unchanged.

CSV and TSV get the same [text](href) cell text, matching what they already get for images.

Test plan

  • New __tests__/table-links.test.tsx covers:
    • Markdown, CSV and TSV exports
    • a table rendered by <Streamdown> with link safety on (the default) and off
    • escaping of the text and address
    • an image inside a link
    • text next to a link
    • autolinks, incomplete links and an <a> without href
  • With lib/ reverted, 6 of its 7 tests fail. The one that still passes is the plain-text case.
  • vitest run in packages/streamdown: 103 files, 1579 tests pass.
  • ultracite check is clean on the changed files.
  • tsc --noEmit reports no new errors (the same count before and after).
  • A patch changeset is included.

extractTableDataFromElement read only a cell's text, so a link lost its
href in every Markdown, CSV and TSV export. Serialise a link as
[text](href) alongside images, and give the link-safety button a
data-href so its address can be read too. Autolinks and links still
streaming in stay plain text.

Fixes vercel#784
@vercel

vercel Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

@mangeshraut712 is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

Comment thread packages/streamdown/lib/table/utils.ts Resolved
Comment thread packages/streamdown/lib/table/utils.ts Resolved
A literal ! immediately before [text](href) was written as an image.
Escape that bang in Markdown so the link is preserved. Labels that only
equal the href, such as /docs, are not autolinks, so they keep
[text](href).

Genuine images, URL/www/email autolinks, and CSV/TSV output are unchanged.
@mangeshraut712

Copy link
Copy Markdown
Author

Follow-up in 6901700: a URL label with a literal space, such as https://example.com/two words, was treated as an autolink when the anchor destination contained %20. That exported only the label, so Markdown could link only the prefix before the space.

Labels containing whitespace now retain explicit Markdown link syntax. The focused serializer assertion reproduced the loss at 1550965 and passed after the fix. The full Streamdown package suite passed locally on Node 24.22.0 with pnpm 10.30.3 after building the workspace dependencies: 103 files, 1,583 tests.

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

✅ All commits are signed

All 4 commit(s) in this pull request have a verified signature. Thanks!

Checked at 707acf6.

@mangeshraut712

Copy link
Copy Markdown
Author

Ready for review. On the current head (707acf667) all check runs pass: Run Tests, verify-changesets, verify-signed-commits, the Socket and Vercel security checks, and the Vercel agent review.

The one red status is the Vercel deployment status, and it is the same on all four commits of this pull request: it links to Vercel's git/authorize page, so the preview deployment is waiting for a Vercel team member to authorize it. That is not something I can do from the fork. Once authorized, the preview should build as on the other pull requests.

This branch has not been deployed

No deployments
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.

Table copy and download drop link URLs, keeping only the link text

1 participant