Preserve line breaks when copying table cells containing <br> elements#554
Open
aradhyacp wants to merge 6 commits into
Open
Preserve line breaks when copying table cells containing <br> elements#554aradhyacp wants to merge 6 commits into
aradhyacp wants to merge 6 commits into
Conversation
- Implemented a new function `extractCellText` to accurately extract text from table cells, handling different node types and line breaks. - Updated `extractTableDataFromElement` to utilize `extractCellText` for header and row cell data extraction. - Modified `escapeMarkdownTableCell` to escape newline characters by converting them to `<br>` tags for proper markdown formatting.
- Introduced a new test suite to verify the preservation of line breaks when copying table data as Markdown, CSV, and TSV. - Ensured that `<br>` tags are correctly handled and do not merge cell text across line breaks. - Mocked clipboard functionality to validate the output format for different copy options.
…ells - Added tests to verify that <br> elements in table cells are correctly converted to newlines. - Included scenarios for handling <br> in nested elements and multiple <br> tags. - Ensured that newlines in table data are converted back to <br> when generating Markdown output.
Contributor
|
@aradhyacp is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
- Streamlined the `extractCellText` function by removing unnecessary line breaks in the return statement, improving code readability.
- Added checks to ensure that the `blobPartsByType["text/plain"]` is defined in multiple test cases. - Improved the `getClipboardPlainText` function to handle optional chaining for better safety. - Reformatted the HTML structure in the test setup for clarity and consistency.
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.
Description
Fixes an issue where copying rendered Markdown tables lost line breaks inside cells containing
<br>elements.Previously, table extraction relied on
textContent, which removed<br>elements without preserving them as newline characters. This caused multiline cell content to be merged together when copying tables as Markdown, CSV, or TSV.This change preserves line breaks during table extraction so copied table content maintains the original formatting.
Type of Change
Related Issues
Fixes #553
Closes #553
Related to #553
Changes Made
textContentbased table cell extraction with a recursive text extraction helper.<br>elements by converting them into newline characters during extraction.<br>elements.Testing
Test Coverage
Added tests covering:
<br>element into a newline.<br>elements into newlines.<br>elements inside nested elements.Manually tested the copy functionality using a local React app.
How I tested it locally:
I used the following test component to verify table rendering and copying behavior:
Screenshots/Demos
Before Markdown Copy
After Markdown Copy
Before CSV Copy
After CSV Copy
Before TSV Copy
After TSV Copy
Checklist
pnpm changeset)Changeset
Additional Notes
This change only affects table text extraction behavior. The existing Markdown, CSV, and TSV serializers continue to handle formatting based on the extracted table data.