Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
FredrikWallstrom opened this issue Oct 9, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@FredrikWallstrom
Copy link
Contributor

FredrikWallstrom commented Oct 9, 2024

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

  • lime-elements version:
  • Framework used:
  • Logs:
@FredrikWallstrom FredrikWallstrom added the bug Something isn't working label Oct 9, 2024
@adrianschmidt
Copy link
Contributor

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 🙂

@john-traas
Copy link
Contributor

This is definitely possible to solve. We've put together the text-editor with a add it when it's needed approach.
I think the main considerations are on how we want to solve it. I think part of the issue will be solved when we solve mentions.

It could be a bit of a rabbit hole and I haven't really gone in-depth to what it might entail.

It could be as pedantic as simply adding a nodeSpec for each type of default HTML tag that we want to support. It might be more complex than that. For mentions we're creating an interface that allows us to specify a tag name (in this case a custom component) and the allowed attributes for that tag. These will most likely be passed as properties to the text editor.

In the text editor we'll have a small factory to create the nodeSpec so the prosemirror adapter can serialize and parse it.
For anyone interested here's the first implementation which is under review: #3139

It might be a bit heavy to expect each consumer to tell the text-editor which HTML tags it want's the editor to recognise. So as far as HTML processing it might be a better option to go with a list of default HTML tags which we pass to the node spec factory on start up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants