Skip to content

Preserve text alignment on Google Docs paste #2149

@caio-pizzol

Description

@caio-pizzol

Summary

Preserve text alignment (center, right, justify) when pasting content from Google Docs into SuperDoc.

Problem

When pasting from Google Docs, all text alignment is lost — everything becomes left-aligned. Google Docs sends text-align as an inline CSS style on <p> elements, but parseAttrs only reads data-* attributes.

Repro

  1. Create a Google Doc with centered, right-aligned, and justified paragraphs.
  2. Copy the content and paste into SuperDoc.
  3. All paragraphs are left-aligned.

Expected

Text alignment from the pasted content is preserved in SuperDoc.

Notes

parseAttrs in packages/super-editor/src/extensions/paragraph/helpers/parseAttrs.js only reads data-indent, data-spacing, and data-num-id/data-level attributes. It never checks node.style.textAlign.

Google Docs sends alignment as inline styles:

style="text-align: center; line-height: 1.38; margin-top: 12pt"

The fix should check node.style.textAlign in parseAttrs and map it to paragraphProperties.justification. The TextAlign extension already uses this path internally via commands.updateAttributes('paragraph', { 'paragraphProperties.justification': alignment }).

File: packages/super-editor/src/extensions/paragraph/helpers/parseAttrs.js


Want to work on this? Check the Contributing Guide to get started. Comment on the GitHub issue to let us know you're picking it up.

copy-paste-test.docx


Want to work on this? Check the Contributing Guide to get started. Comment on this issue to let us know you're picking it up.

Ref: SD-1978

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions