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

Pasting some text from Google docs or Words adds additional br #683

Closed
srenault opened this issue Aug 4, 2017 · 8 comments
Closed

Pasting some text from Google docs or Words adds additional br #683

srenault opened this issue Aug 4, 2017 · 8 comments

Comments

@srenault
Copy link

srenault commented Aug 4, 2017

When I past some content from Google docs or Words, a new line is converted into:

screen shot 2017-08-04 at 15 50 48

As you can see, we have two br instead of one.
This can be easily reproduced by copy/paste this content into your basic example.
I tried to investigate the issue and identified that the additional br is created here.
If you guide me, I can try to propose a PR.

@srenault srenault changed the title Pasting some text from Google docs or Words add additional br Pasting some text from Google docs or Words adds additional br Aug 4, 2017
@marijnh
Copy link
Member

marijnh commented Aug 5, 2017

The second <br> is part of the presentation layer, used to make the first one visible to the user, and not actually part of the document.

@marijnh marijnh closed this as completed Aug 5, 2017
@srenault
Copy link
Author

srenault commented Aug 5, 2017

Yes, but the second br make the display buggy. We actually think we have two lines.

screen shot 2017-08-05 at 10 34 30

Maybe I miss something. Thanks.

@marijnh
Copy link
Member

marijnh commented Aug 5, 2017

What did you expect a paragraph with only a hard break to look like? The same as an empty one?

(It will look like an empty one, when rendered to uneditable HTML, but during editing, it is important to be able to place the cursor both before and after the existing hard break, so ProseMirror renders it like this.)

@srenault
Copy link
Author

srenault commented Aug 5, 2017

Yes I expect that the new line copied from Words or Google Docs be converted into an empty paragraph.

<p>
 <br/>
</p>

@marijnh
Copy link
Member

marijnh commented Aug 5, 2017

An empty paragraph is <p></p>, and is distinct from a paragraph with a hard break in it. Is the original <br> something you'd want to be ignored/dropped on paste?

@srenault
Copy link
Author

srenault commented Aug 5, 2017

Yep, I think so.

@marijnh
Copy link
Member

marijnh commented Aug 5, 2017

You could get that effect with a transformPasted prop that drops trailing hard breaks. Or, alternatively, you could see if Google Docs/Word add any attribute to such hard breaks that can be used to target them for ignoring with a parse rule.

This is probably not something ProseMirror core will ever handle out-of-the-box, but I'm hoping someone will at some point set up a 'paste from word processors' plugin module that helps handle the weird markup that the various word processors put on the clipboard.

@srenault
Copy link
Author

srenault commented Aug 5, 2017

Okey thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants