aieditor-team / AiEditor

AiEditor is a next-generation rich text editor for AI.
https://AiEditor.dev
GNU Lesser General Public License v2.1
1.1k stars 115 forks source link

pasteAsText: true configuration option ignores headings #92

Closed TobiasKrais closed 2 months ago

TobiasKrais commented 2 months ago

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 commented 2 months ago

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

TobiasKrais commented 2 months ago

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

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 commented 2 months ago

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

TobiasKrais commented 1 month ago

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

yangfuhai commented 1 month ago

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

TobiasKrais commented 1 month ago

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

TobiasKrais commented 1 month ago

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;
                        }
                    },