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

pasteAsText: true configuration option ignores headings #92

Closed
TobiasKrais opened this issue Sep 26, 2024 · 7 comments
Closed

pasteAsText: true configuration option ignores headings #92

TobiasKrais opened this issue Sep 26, 2024 · 7 comments

Comments

@TobiasKrais
Copy link
Contributor

When pasteAsText: true is activated in configuration, text is pasted without formatting. When copied text includes a heading like h1, the editor shows it as h1 heading. Other editors like TinyMCE paste headings also as plain text.

@yangfuhai
Copy link
Contributor

If I add a custom configuration for tag filtering, will it be more flexible? Will it meet this requirement?

@TobiasKrais
Copy link
Contributor Author

Other editors offer several paste function. E.g. TinyMCE or CKE offers:

  • paste (rich text)
  • pasteWord (paste from word and removes not necessary formattings)
  • pasteAsText (plain text)

I think we should use pasteAsText as what it is and what is common use: paste as plain text. That is also my requirement. If you want, you can additionally offer other functionality to discern from other editors, e.g. pasteAsSimpleHtml. But that is not my requirement.

@TobiasKrais
Copy link
Contributor Author

The only "formatting" pasteAsText commonly supports are line breaks that are interpreted as <br> or <p>.

@TobiasKrais
Copy link
Contributor Author

Thank you for the fix last week. Please not that pasteAsText still has not the common use. Line breaks are not preserved.

@yangfuhai
Copy link
Contributor

hi @TobiasKrais , the Line breaks are be preserved if config the pastedAsText ? if yes, i will continue to optimize this issue.

@TobiasKrais
Copy link
Contributor Author

TinyMCE and other editors convert line breaks to <br>. Thus paragraphs are kept for users.

@TobiasKrais
Copy link
Contributor Author

This is my workaround in editor config:

                    htmlPasteConfig: {
                        pasteProcessor: (html) => {
                            // Create a temporary DOM element
                            let tempDiv = document.createElement('div');
                            tempDiv.innerHTML = html;
                        
                            // Extract text content and replace newlines with <br> tags
                            let formattedContent = tempDiv.innerText.replace('/\\n/g', '<br>');                        
                            return formattedContent;
                        }
                    },

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