Skip to content

fix: Preserve table cell styles on Google Docs paste#2628

Open
Branc0 wants to merge 15 commits intosuperdoc-dev:mainfrom
Branc0:2150-preserve-table-styles
Open

fix: Preserve table cell styles on Google Docs paste#2628
Branc0 wants to merge 15 commits intosuperdoc-dev:mainfrom
Branc0:2150-preserve-table-styles

Conversation

@Branc0
Copy link
Copy Markdown
Contributor

@Branc0 Branc0 commented Mar 30, 2026

Summary

PR for the issue Issue #2150.

Table cell styling is lost when pasting from Google Docs. Cells with background colors are pasted as plain white; borders and padding are dropped.

Additionally, as a side effect of the main fixes, this PR solves two other issues:

  • Google Docs Pasted tables don't persist row height: I had to fix to test vertical alignment.
  • Duplicated borders on the intersections of cells. As we make the borders bigger, this gets more evident.

Steps for testing

  • Create a table in Google Docs with colored cells (e.g., this doc ).
  • Copy the table and paste it into SuperDoc.
  • Table cell background colors, borders, padding, and vertical alignment from pasted content are preserved.

const [bottomValuePt] = parseSizeUnit(style?.paddingBottom);
const [leftValuePt] = parseSizeUnit(style?.paddingLeft);

const top = halfPointToPixels(topValuePt);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was searching for a helper function that converts PT to PX, and I noticed this has the same formula, so I used it despite the name being halfPoint. Let me know if it's okay...

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.

@Branc0 the formula is right, just the name is confusing — we mentioned a shared helper in the inline review.

@Branc0 Branc0 marked this pull request as ready for review March 30, 2026 01:21
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5b77732f99

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +82 to +83
right: cellBounds.touchesRightEdge ? resolveTableBorderValue(cellBorders.right, tableBorders.right) : undefined,
bottom: touchesBottomBoundary ? resolveTableBorderValue(cellBorders.bottom, tableBorders.bottom) : undefined,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve explicit interior cell borders in collapsed mode

In resolveRenderedCellBorders, the collapsed-table branch drops right/bottom for every non-edge cell even when those sides are explicitly set on the cell. This means interior overrides (for example a custom right border on one cell) are silently replaced by table defaults or disappear entirely when insideV/insideH is absent, so pasted/imported tables lose intended border styling whenever tableBorders exists.

Useful? React with 👍 / 👎.

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.

@Branc0 this is intentional — Google Docs always puts the same border on both sides, so nothing gets lost.

@Branc0
Copy link
Copy Markdown
Contributor Author

Branc0 commented Mar 30, 2026

Still WIP on this one:

  • The P1 issue from codex: tried a couple of fixes, but they introduced the duplicated border back
  • Integration test

@caio-pizzol caio-pizzol self-assigned this Mar 30, 2026
Copy link
Copy Markdown
Contributor

@caio-pizzol caio-pizzol left a comment

Choose a reason for hiding this comment

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

@Branc0 tested with real Google Docs tables — backgrounds, borders (solid/dashed/dotted), merged cells, borderless cells, padding, column widths all working. no blockers.

test docs: basic styles · edge cases

basic styles — GDocs vs SuperDoc:
image
image

edge cases — GDocs vs SuperDoc:
image
image

left a few inline comments.

@@ -0,0 +1,52 @@
// @ts-check
Copy link
Copy Markdown
Contributor

@caio-pizzol caio-pizzol Mar 30, 2026

Choose a reason for hiding this comment

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

re: halfPointToPixels — same formula is now in three files. a small shared helper would keep it in one place, worth doing before more paste handlers land?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@caio-pizzol, we briefly spoke about this on Friday morning, but I forgot the outcome of our discussion 😅.

halfPointToPixels is already coming from "@core/super-converter/helpers.js", do you want me to change its name, or keep it as it is?

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.

keep the name, it's fine. the duplication is minor — not worth extracting for this PR.

@caio-pizzol
Copy link
Copy Markdown
Contributor

Hey @Branc0, this PR has had no activity for 3 days.

Copy link
Copy Markdown
Contributor

@caio-pizzol caio-pizzol left a comment

Choose a reason for hiding this comment

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

@Branc0 tests and comment look good, resolved those two threads.

one thing: Google Docs uses <th> for header rows, but table-header.js only has rendering — it's missing the parsing side for the new attributes. so when you paste a table with a header row, the header cells lose their padding (and would lose background/borders/alignment too if they had any). table-cell.js has both sides, table-header.js needs the same. tested with this doc.

re: the halfPointToPixels name — keep it as is, it's fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants