This is a migrated thread and some comments may be shown as answers.

HTML paragraph tag inserted when copy/paste from MS Word

3 Answers 107 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Amy
Top achievements
Rank 1
Amy asked on 01 Feb 2011, 09:31 PM
Hello!  I have noticed when copying text from MS Word into the RadEditor an opening and closing paragraph tag is being inserted/wrapped around the text.  Is there any way to just remove only the paragraph tag using the 'Formatting Stripper' option in the RadEditor?

I tried the 'Strip Word Formatting' but that has no effect on the HTML tags (as expected).  The 'Strip All Formatting' option will remove the paragraph tags but also removes other formatting that may be desired/necessary such as bolding, italics, etc.

I also tried the 'Paste From Word' button on the RadEditor toolbar, but it has the same effects described above for the 'Format Stripper' button.

I looked through the 'Editing/Cleaning Word Formatting' demo and the 'Cleaning Word Formatting' article but was unable to find a solution related to the paragraph tags.

Thanks!

3 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 04 Feb 2011, 12:33 PM
Hello Amy,

RadEditor does not offer a paragraph strip functionality and to achieve it you can attach to the OnClientPasteHtml event of RadEditor and strip the desired tags with your own regular expression. The OnClientPasteHtml event is useful in scenarios where the developers need to examine or modify the HTML to be pasted by an editor tool before it is inserted in the editor content area. Some common cases where the event can be used are:
  • Modify the pasted content before its insertion in the content area
  • Check whether user specified alt attribute for an image
  • Make modifications to a table being inserted (e.g. set a specific classname, etc)
  • Examine or modify a link before it is inserted

Kind regards,
Rumen
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Mac P
Top achievements
Rank 1
answered on 17 Sep 2013, 08:05 PM
Hello,

I have similar problem when pasted from large word document it leaves so much blank paragraphs and looses formatting. I have used paste option to strip word as well but i am not sure what should be the solution. Do you have a fix for this? I tried looking for regex but cannot find anything useful.
I also tried pasting on telerik's demo website to see if newer version fixes this issue.  But no luck.

Attached is the file that shows the issue in detail.

I also tried following code on ClientPasteHtml but no use.
function OnClientPasteHtml(sender, args) {
            var commandName = args.get_commandName();
            var value = args.get_value(); //this is the pasted content 
            if (commandName == "Paste") {
                var htmlText = value + "";
                htmlText = htmlText.replace(/(<[^>]*style=["'])([^"']*)(["'][^>]*>)/gi, function (match, group1, group2, group3, offset, fullText) {
 
                    var resultText = group1;
                    group2 = group2.replace(/(background|-webkit-background)-?[a-z]*: initial;/gi, "");
                    group2 = group2.replace(/line-height: normal;?/gi, "");
                    resultText += group2;
                    resultText += group3;
                    return resultText;
                });
                 
                args.set_value(htmlText);  //insert the modified content in the editor 
            }
        }
Regards
0
Marin Bratanov
Telerik team
answered on 20 Sep 2013, 08:49 AM
Hi Mac,

This problem stems from MS Word - the empty lines in your document are actually paragraphs in MS Word, so when pasted and converted to HTML you get empty paragraph tags. This is explained in the following KB that we just updated with a workaround for this MS Word behavior: http://www.telerik.com/support/kb/aspnet-ajax/editor/appearance-of-extra-lines-when-pasting-from-ms-word.aspx.


Regards,
Marin Bratanov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Editor
Asked by
Amy
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Mac P
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or