basecamp / basecamp/trix

Extra Newlines Introduced in Trix 2.1.14 when Pasting Content from Microsoft Editor

Open
#1,242 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
20k
Forks
1.1k
Avg merge
3d 12h
Merged PRs (30d)
13

Description

To recreate the problem:

1. Start to compose an email in Outlook.
2. Enter two lines of text like:
```
Line 1
Line 2
```
3. Select the text and copy it to the clipboard.
4. Paste it into a Trix editor.

In Trix 2.1.13, this will paste correctly and the text will look like this:

```
Line 1
Line 2
```

In Trix 2.1.14, this will add extra newlines and will look like this:

```

Line 1

Line 2
```

I am testing Trix in an HTML document like this:

```html







```

Trix `2.1.14` has the issue. `2.1.13` does not.

This issue also affects text cut and pasted from other Microsoft apps like Word.

Something about the DOMPurify upgrade changed this behavior. In the old version, when `HTMLSanitizer.setHTML` is called, `this.containerElement` gets set with HTML like:

```html


Line 1


Line 2

<!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;
mso-font-charset:0;
mso-generic-font-family:roman;
mso-font-pitch:variable;
mso-font-signature:-536870145 1107305727 0 0 415 0;}
@font-face
{font-family:Aptos;
panose-1:2 11 0 4 2 2 2 2 2 4;
mso-font-charset:0;
mso-generic-font-family:swiss;
mso-font-pitch:variable;
mso-font-signature:536871559 3 0 0 415 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-unhide:no;
mso-style-qformat:yes;
mso-style-parent:"";
margin:0in;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Aptos",sans-serif;
mso-fareast-font-family:Aptos;
mso-bidi-font-family:Aptos;}
.MsoChpDefault
{mso-style-type:export-only;
mso-default-props:yes;
font-size:10.0pt;
mso-ansi-font-size:10.0pt;
mso-bidi-font-size:10.0pt;
mso-font-kerning:0pt;
mso-ligatures:none;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;
mso-header-margin:.5in;
mso-footer-margin:.5in;
mso-paper-source:0;}
div.WordSection1
{page:WordSection1;}
-->


```

In version `2.1.14`, the `` element is no longer present and this seems to affect how the newlines are introduced. If I manually add the `<style>` element back in after `HTMLSanitizer.setHTML` is called then the problem is fixed.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at HTMLSanitizer.setHTML and compare the sanitized clipboard DOM in Trix 2.1.13 and 2.1.14, focusing on the missing style element after the DOMPurify upgrade. Reproduce paste and cut from Outlook or Word, then confirm that the resulting Trix content has no extra newlines while preserving normal line breaks.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.