In Correct data getting on OnClientPasteHtml from RadEditor

2 posts, 0 answers
  1. Anwar
    Anwar avatar
    31 posts
    Member since:
    Aug 2011

    Posted 30 May 2013 Link to this post

    HI,

    i am pasting bellow content in RadEditor's  through OnClientPasteHtml function,
    hello<br><br><a href="http://www.gmail.com">gmail</a><br><br><a href="http://www.facebook.com">facebook</a><br><br><br>If you no longer wish to receive these emails, simply click on the following link:<a href="[!RPLINK:GLOBALUNSUBSCRIBE!]">Unsubscribe</a>

    after pasting the data displaying as
    hello&lt;br&gt;&lt;br&gt;&lt;a href="<a href='http://www.gmail.com">gmail</a><br><br><a'>http://www.gmail.com"&gt;gmail&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;a</a> href="<a href='http://www.facebook.com">facebook</a><br><br><br>If'>http://www.facebook.com"&gt;facebook&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;If</a> you no longer wish to receive these emails, simply click on the following link:&lt;a href="[!RPLINK:GLOBALUNSUBSCRIBE!]"&gt;Unsubscribe&lt;/a&gt;

    checkout anchor tag structure is not in proper in content after pasting.

    Editor properties, 
    <telerik:RadEditor ID="textRadEditor" EditModes="Design" runat="server" Width="100%"
        EnableResize="false" OnClientLoad="GetContentLength" OnClientPasteHtml="OnClientPasteHtmlToText" 
        Height="550px">
        <Tools>
            <telerik:EditorToolGroup>
                <telerik:EditorTool Name="convertToTEXT" Text="Convert HTML to TEXT" ShowText="true"
                    ShowIcon="false" />
                <telerik:EditorSeparator />
                <telerik:EditorTool Name="InsertEditorLinks" ShowIcon="false" ShowText="true" Text="Insert Link" />
            </telerik:EditorToolGroup>
        </Tools>
        <CssFiles>
            <telerik:EditorCssFile Value="~/Editor/RadEditorTools/EditorContentArea.css" />
        </CssFiles>
    </telerik:RadEditor>

    Script,
    function OnClientPasteHtmlToText(sender, args) {
                //debugger;           
                var val = args.get_value();
                var name = args.get_name();
                if (name == "Paste") {
                    //debugger;
                    var editor = $find("<%=textRadEditor.ClientID%>")
                    if (document.getElementById("hdTextPaste").value != "true") {
                        var oSelElem1 =val ;
                        var pattern = /<a[^>]*>(.*?)<\/a>/gi
                        var code = oSelElem1.match(pattern);
                        if (code != null) {
                            for (i = 0; i < code.length; i++) {
                                var url = code[i].match(/href=\"(.*?)\"/)[1];
                                var text = code[i].match(/<a[^>]*>(.*?)<\/a>/)[1];
                                if (text.toLowerCase().search("<img") >= 0)
                                    oSelElem1 = oSelElem1.replace(code[i], url);
                                else
                                    oSelElem1 = oSelElem1.replace(code[i], text + ':' + url);
                            }
                            editor.pasteHtml(oSelElem1);
                            var plainText = editor.get_text();
                            editor.set_html("");
                            plainText = plainText.replace(/((\r\n|\r|\n)\s*)\2/g, "$2");
                            plainText = plainText.replace(/\t/g, '    ').replace(/  /g, '&nbsp; ').replace(/\r\n|\n|\r/g, '<br />');
                            editor.set_html(plainText);
                            document.getElementById('<%= hdCampEditorTab2.ClientID %>').value = "1";                        
                        }


                    }

                }
            }

    any idea?

    Regards,
    Anwar
  2. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1502 posts

    Posted 04 Jun 2013 Link to this post

    Hi Anwar,

    Note that when you copy text (no matter whether it is in HTML format) from a document file and then paste it in the RadEditor, special symbols will be encoded. If you copy, however, a markup from a web page and then paste it into the RadEditor's content area the special symbols will not be encoded as they are perceived as HTML.

    Regarding the correctness of the pasted content in RadEditor, I have tested that by inspecting the content of the oSelElem1variable in the JavaScript code and everything seems to be fine on my side. You can find a short video with the test in the attached archive. The regular expressions code below the oSelElem1 variable, however, is a custom solution. Therefore it is up to the developer how to create and verify it.


    Regards,
    Danail Vasilev
    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 their blog feed now.
Back to Top