Skip to content

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

Open
mangeshraut712 wants to merge 1 commit into
vercel:mainfrom
mangeshraut712:fix/table-export-links
Open

mangeshraut712 wants to merge 1 commit 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.

const text = inner.text.replace(/\r\n|[\r\n]/g, (match) =>
" ".repeat(match.length)
);
return `[${escapeCellKeepingImages(text, inner.images)}](${encodeImageSrc(href)})`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A literal ! immediately before a cell link combines with the new [text](href) output to produce an image instead of a link.

Fix on Vercel

Comment on lines +120 to +125
return [text, `http://${text}`, `mailto:${text}`].some(
(candidate) =>
candidate === href ||
candidate === decoded ||
(target !== undefined && normalizeUrl(candidate) === target)
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Links such as [/docs](/docs) and [example.com](http://example.com/) are incorrectly classified as autolinks, so their exported Markdown loses the clickable link.

Fix on Vercel

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