HTML paragraph tag inserted when copy/paste from MS Word

4 posts, 0 answers
  1. Amy
    Amy avatar
    113 posts
    Member since:
    Aug 2010

    Posted 01 Feb 2011 Link to this post

    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!
  2. Rumen
    Admin
    Rumen avatar
    14351 posts

    Posted 04 Feb 2011 Link to this post

    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.
  3. Mac P
    Mac P avatar
    86 posts
    Member since:
    Mar 2010

    Posted 17 Sep 2013 Link to this post

    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
  4. Marin Bratanov
    Admin
    Marin Bratanov avatar
    5440 posts

    Posted 20 Sep 2013 Link to this post

    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.
Back to Top