Repository navigation
fix(table): keep link addresses in table copy and download - #786
Open
mangeshraut712 wants to merge 1 commit into
Open
mangeshraut712 wants to merge 1 commit into
mangeshraut712 wants to merge 1 commit into
Conversation
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
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)})`; |
Contributor
Comment on lines
+120
to
+125
| return [text, `http://${text}`, `mailto:${text}`].some( | ||
| (candidate) => | ||
| candidate === href || | ||
| candidate === decoded || | ||
| (target !== undefined && normalizeUrl(candidate) === target) | ||
| ); |
Contributor
This branch has not been deployed
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.
Fixes #784.
Summary
When a table is copied or downloaded from its controls, links lose their address and only the link text is kept.
extractTableDataFromElementreads each cell's text nodes, so an<a href>contributes its text and drops thehref.This PR serialises a link in a cell as
[text](href), the same way images are already exported as:[](…)round-trips.(,),|and spaces can't end the link early.tableDataToMarkdownleaves it unescaped andTableDatakeeps its shape.<button>with nohref. The button now carries the address indata-href, so these links are exported too. This was the case in the issue's repro with link safety on.https://…,www.…, or an email).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
__tests__/table-links.test.tsxcovers:<Streamdown>with link safety on (the default) and off<a>withouthreflib/reverted, 6 of its 7 tests fail. The one that still passes is the plain-text case.vitest runinpackages/streamdown: 103 files, 1579 tests pass.ultracite checkis clean on the changed files.tsc --noEmitreports no new errors (the same count before and after).