Lundalogik / lime-elements

Provides reusable web components for Lime CRM
https://lundalogik.github.io/lime-elements/versions/latest
Other
38 stars 11 forks source link

text-editor: HTML styling is stripped away when editor is prepopulated #3236

Open FredrikWallstrom opened 2 days ago

FredrikWallstrom commented 2 days ago

Current behavior

When you prepopulate the editor with some HTML, for example an email, some styling is stripped away. Unfortunately, I haven't been able to locate exactly where this happen because I'm not that familiar with the prosemirror-adapter.

EDIT: It actually looks like prosemirror is rewriting the entire HTML. Tags are replaced, for example div tags is replaced with p tags, b tags is replaces with strong tags. In most cases, this might be OK, but in other cases it might have fatal consequences, for example with table tags, as they are completely removed and the table content is replaced with p tags.

If I remove the change handler for the value, my HTML is kept with full styling when it is display in the markdown component in the feed. If I have the change handler in place, and I change something in the editor, the HTML styling is lost. This is a sign for me that the HTML is manipulated in the prosemirror-adapter somewhere.

Steps to reproduce the behavior:

        this.body = "<div style='color: red'>RED COLOR</div>"

        return [
            <limel-text-editor
                onChange={this.handleBodyChange}
                value={this.body}
                contentType={'html'}
            />,
            <limel-markdown value={this.body}/>,
        ];

Produces the following:

Skärmavbild 2024-10-09 kl  07 32 00

Readonly editor mode: Skärmavbild 2024-10-09 kl  07 18 57

Not readonly mode produces the following: Skärmavbild 2024-10-09 kl  07 19 11

Change handler removed, HTML styling is kept in the feed: Skärmavbild 2024-10-09 kl  07 26 56

The value has changed, HTML styling is not kept in the feed: Skärmavbild 2024-10-09 kl  07 27 46

Expected behavior

Styling should not be stripped away from the HTML.

Environment

adrianschmidt commented 1 day ago

I thought I'd throw in a link to the Slack thread about this bug here: https://lime-technologies.slack.com/archives/C1K6TN9BK/p1728391028828459

I haven't read it yet, so I don't know if there's anything in there that isn't in the issue description, but I wanted the reference to the thread on this issue, just in case 🙂