Fix extra list indentation when pasting from Word Desktop#3330
Fix extra list indentation when pasting from Word Desktop#3330BryanValverdeU merged 6 commits intomasterfrom
Conversation
When pasting from Word Desktop, Word's global stylesheet includes margin declarations on p.MsoListParagraph, div.MsoListParagraph, and their CxSpFirst/Middle/Last variants. These global CSS rules were being applied as inline styles before RoosterJS processed the list structure, causing double-indentation on pasted lists. - Add globalCssRules to BeforePasteEvent and promote CssRule to a public type in roosterjs-content-model-types - Pass globalCssRules into the BeforePasteEvent from generatePasteOptionFromPlugins - Add removeListParagraphMargins.ts which strips margin-* properties from global CSS rules targeting the Word list paragraph classes; mixed-selector rules are split so only the matching selectors lose their margins - Wire removeListParagraphMargins into processPastedContentFromWordDesktop via a new globalCssRules parameter, passed through from PastePlugin - Set browser in karma client config so itChromeOnly works correctly with the fast config Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses double-indentation on lists pasted from Word Desktop by preventing Word’s global CSS margins (for p/div.MsoListParagraph*) from being inlined before RoosterJS list processing.
Changes:
- Promotes
CssRuleto a public type and addsglobalCssRulestoBeforePasteEvent, then threadsglobalCssRulesthrough the paste pipeline. - Adds
removeListParagraphMarginsto stripmargin*properties from Word list-paragraph global CSS rules (splitting mixed-selector rules as needed). - Updates Word Desktop paste processing to apply the new global CSS rule sanitization and adds/updates unit tests.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/roosterjs-content-model-types/lib/index.ts | Re-exports CssRule from types entrypoint for consumers. |
| packages/roosterjs-content-model-types/lib/event/BeforePasteEvent.ts | Adds CssRule type + globalCssRules field on BeforePasteEvent. |
| packages/roosterjs-content-model-plugins/lib/paste/WordDesktop/removeListParagraphMargins.ts | New helper that removes margin properties from Word list-paragraph CSS rules. |
| packages/roosterjs-content-model-plugins/lib/paste/WordDesktop/processPastedContentFromWordDesktop.ts | Wires removeListParagraphMargins into Word Desktop paste handling via new globalCssRules param. |
| packages/roosterjs-content-model-plugins/lib/paste/PastePlugin.ts | Passes event.globalCssRules into Word Desktop processing. |
| packages/roosterjs-content-model-core/lib/command/paste/generatePasteOptionFromPlugins.ts | Populates BeforePasteEvent.globalCssRules from retrieveHtmlInfo. |
| packages/roosterjs-content-model-core/lib/command/paste/retrieveHtmlInfo.ts | Uses the shared CssRule type and returns extracted globalCssRules. |
| packages/roosterjs-content-model-core/lib/command/createModelFromHtml/convertInlineCss.ts | Switches to importing CssRule from roosterjs-content-model-types. |
| packages/roosterjs-content-model-core/test/command/paste/generatePasteOptionFromPluginsTest.ts | Updates expectations to include globalCssRules. |
| packages/roosterjs-content-model-plugins/test/paste/word/removeListParagraphMarginsTest.ts | Adds unit coverage for margin-stripping behavior (including mixed-selector splitting). |
| packages/roosterjs-content-model-plugins/test/paste/word/processPastedContentFromWordDesktopTest.ts | Updates test harness to pass CSS rules into Word Desktop processor. |
| CLAUDE.md | Adds reference to AGENTS.md. |
| AGENTS.md | Adds repo guidance (architecture + commands). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| selectors: string[]; | ||
| text: string; | ||
| } | ||
| import type { CssRule } from 'roosterjs-content-model-types'; |
There was a problem hiding this comment.
convertInlineCss.ts used to export a CssRule interface, but this change removes that export. There are existing imports (e.g. unit tests and potentially downstream internal code) that import CssRule from this module, which will now fail to compile. To preserve compatibility, re-export the new public CssRule type from roosterjs-content-model-types (type-only export) or update all import sites in the repo accordingly.
| import type { CssRule } from 'roosterjs-content-model-types'; | |
| import type { CssRule } from 'roosterjs-content-model-types'; | |
| export type { CssRule } from 'roosterjs-content-model-types'; |
…/roosterjs into u/bvalverde/pasteWord1
When pasting from Word Desktop, Word's global stylesheet includes margin declarations on p.MsoListParagraph, div.MsoListParagraph, and their CxSpFirst/Middle/Last variants. These global CSS rules were being applied as inline styles before RoosterJS processed the list structure, causing double-indentation on pasted lists.