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

Strip / Remove : MS Word, HTML, etc from content when pasting into RadEditor

14 Answers 777 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Travas Nolte
Top achievements
Rank 1
Travas Nolte asked on 12 Dec 2008, 05:44 PM
I am using the RadEditor (version: 2008.3.1105.35) within the RadGrid template edit form as a model popup.

I have a client application that allows them to enter comments into the RadEditor. These comments need to be free of HTML because the data will be used with .PDF reports. The users are using all types of browsers (IE, FF, and Safari). The users are copying content from Word and from other HTML on pages and pasting it into the editor. I have the StripFormattingOptions set to "AllExceptNewLines", but it doesn't appear to be working, It appears that nothing is getting removed.

What is the correct way to configure the RadEditor to remove all HTML/MS Word formatting and only leave new lines when users paste content using IE, FF and Safari browsers?

Are there any server side methods of scrubbing/cleaning the content before it's commited to the database? Cient-side?



 

14 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 15 Dec 2008, 05:28 PM
Hi Travas,

I was unable to reproduce the problem in Internet Explorer where the content was stripped as expected. However, I was able to reproduce that the StripFormattingOptions options AllExceptNewLines and All do not strip the ms word formatting in Firefox 3, because the style tag containing the whole word formatting classes is not stripped from the pasted content.  I logged the problem in our bug tracking system and notified our developers about it. We will do our best to fix this problem in one of the next hotfixes of RadEditor.

I also updated your Telerik points.

As to the Safari problem: Safari still does not offer an onpaste event in difference with Internet Explorer and Firefox 3. This means that there is no way to detect when the paste operation occurs under Safari and strip the content. That is why the StripFormattingOnPaste option works currently only under IE and Firefox 3.

My suggestion is to strip the Word formatting when submitting the content to the server using the code below:

<script type="text/javascript">
function OnClientLoad(editor, args)
{
  editor.add_submit(function ()
  {
     editor.fire("SelectAll");
     editor.fire("FormatStripper", {value : "ALL_NO_BRAKES"});
     alert(editor.get_html());
});
}
</script>
<telerik:radeditor runat="server" OnClientLoad="OnClientLoad" ID="RadEditor1">
  <Content>
     
      <p><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">  </p>
      <p class=MsoNormal><b style="mso-bidi-font-weight: normal"><span style="FONT-SIZE: 10pt; BACKGROUND: red; COLOR: #ff9900; mso-bidi-font-family: Arial; mso-highlight: red">Sampe MS Word content</span></b><b style="mso-bidi-font-weight: normal"><span style="FONT-SIZE: 10pt; COLOR: #ff9900; mso-bidi-font-family: Arial"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></span></b></p></span></span>
     
  </Content>
</telerik:radeditor>
<asp:Button ID="Button1" runat="server" Text="Submit" />
   

Best regards,
Rumen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
hacker
Top achievements
Rank 1
answered on 26 Feb 2009, 05:52 PM
Hello, I am running into this issue using FF3 as well.  I have installed Q1 2009 Beta and it still seems to be an issue.  Will this be fixed when the actual release is complete?

Shawn
0
Rumen
Telerik team
answered on 03 Mar 2009, 04:35 PM
Hi Shawn,

Could you please confirm that you are talking about the problem that appears when the
StripFormattingOptions property is set to "All" and "AllExceptNewLines"? In this scenario the content of pasted STYLE tag with word formatting is not stripped in FF3 and its content is rendered in Design mode.

This bug is still not fixed but I raised its priority in our bug tracking system.
I notified our developers about the issue once again and we will try to fix it for the official Q1 2009 release of RadControls for ASP.NET AJAX. If the time does not permit to fix the problem for Q1 2009, then we will do our best to solve it for the Q1 SP1 release.

Kind regards,
Rumen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
hacker
Top achievements
Rank 1
answered on 03 Mar 2009, 04:56 PM
When I set it to just "All" none of the formatting is stripped when looking at the HTML view.  I still see the <style> tag with all the Word formatting stuff.  When I set it to All and AllExceptNewLines, I get something different.  This is pasted in the window:
Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;} Heading   This is the text  

I am using Q1 2009 in Firefox 3.0.6.

When I use IE, with either setting, it just displays the text:
Heading   This is the text

Shawn
0
Rumen
Telerik team
answered on 05 Mar 2009, 03:30 PM
Hi Shawn,

This is exactly the same problem. Unfortunately we will not have enough time to solve the issue for the Q1 release, scheduled for 10th of March, because the time is not enough and we will need to perform detailed test after that. We will do our best to fix the bug for SP1 that goes after the Q1 release.

Kind regards,
Rumen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
hacker
Top achievements
Rank 1
answered on 05 Mar 2009, 03:34 PM
Thanks for the information Rumen.

In my case, it is still in development, so I have some time before it will go live. 

Shawn
0
Brian Goldman
Top achievements
Rank 2
answered on 06 Mar 2009, 07:06 PM
Unfortunately for me I have to buy a different editor to get a project done. I'm not exactly happy about it. This is the first big problem I've ran into with telerik products, hopefully the last.
I demoed a lot of editors online and it seems that a lot of them have the same problem. The only one I found that handled it well is cutesoft's editor so I guess I have to give them some money.

0
Rumen
Telerik team
answered on 07 Mar 2009, 04:42 PM
Hi guys,

You can try the following workaround that will strip the <style> tag with word formatting on paste. Here is a sample code that will be executed when the onpaste event is fired:

<script type="text/javascript">  
function OnClientPasteHtml(sender, args)  
{  
    var commandName = args.get_commandName();  
    var text = args.get_value(); //get the pasted value  
      
    if ($telerik.isFirefox)  
    {  
            text = text.replace(/<!--(.|\s)*?-->/gi,""); //strip the style tag content  
            args.set_value(text);  //set the modified content in the editor  
    }  
}  
</script>  
  
<telerik:RadEditor runat="server" StripFormattingOptions="MSWordRemoveAll,Css,Font,Span" OnClientPasteHtml="OnClientPasteHtml"  
    ID="RadEditor1" >  
</telerik:RadEditor>  


Best regards,
Rumen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Brian Goldman
Top achievements
Rank 2
answered on 09 Mar 2009, 07:05 PM
Thanks Rumen, that seem to work pretty well. One problem I noticed that you may be able to help me with is that pasting bullet points from word 2007 doesn't build an unordered list. It gives this code
<style>  </style> <p><b>This is a test</b></p> <p><i>This is a test</i></p> <p><u>This is a test</u></p> <p>·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; This is a test bullet<u></u></p> <p>·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; This is a test bullet<u></u></p>

This problem doesn't seem to happen when pasting from word 2003, it seems to work properly with word 2003


Thanks,
Brian




0
hacker
Top achievements
Rank 1
answered on 10 Mar 2009, 01:51 PM
This seems to do the trick for me.  I haven't tested it extensively, but for a quick paste from Word, it works. 

Thanks for the quick fix!
Shawn
0
Rumen
Telerik team
answered on 12 Mar 2009, 01:43 PM
Hi guys,

Let me provide you with more details what is happening when pasting content with bullets from MS Word 2007. The paste process is controlled entirely by the Operating System and by the browser. The editor is not allowed to interfere in this process much (of course there are some minor differences between browsers). Thus, with respect to pasting - the original MS Word formatting is not HTML. It is MS Word specific XML formatting. When this is exported to the clipboard, and is made available for paste, it "announces" what "paste flavors" it supports - and those would be MS Word, HTML, plain text, RTF and so on. When a client entity (such as the editor) wants to consume the content of the clipboard, it announces what paste formats it supports (and the editor - any editor - only supports plain text and HTML). So, MS Word converts the original MS Word to HTML, and this process is controlled entirely by MS Word, and not at all possible to interfere by the editor. This is why you would notice the same results in IE, FireFox, Opera, and any other browser that supports rich-text editing.

Indeed, Office 2003 exports lists to HTML using <UL> tags (which is the proper way), however Office 2007 exports those using P and SPAN tags (which is a strange decision, but the editor has nothing to do with it).

Unfortunately, it is not possible to change this behavior. You will get this behavior with our competitors' editors, with RadEditor and with any other web-based editor you decide to try.

I hope that this information will be helpful for our community.

Best regards,
Rumen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Richard Buff
Top achievements
Rank 1
answered on 16 Feb 2010, 09:59 PM

Hi, Telerik folks,

We are also experiencing the same issue.  Am I reading right that this won't be fixed because it's "default" behavior?


Looks like CuteSoft has fixed it, so we know that not all of the competing editors have the issue.

Thanks!
Rich
0
Rumen
Telerik team
answered on 17 Feb 2010, 07:43 AM
Hi Richard,

I have good news that the requested functionality was implemented in Q3 2009 SP2 (version 2009.3.1314) and you can test it in the live example: Default Settings.

Greetings,
Rumen
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Richard Buff
Top achievements
Rank 1
answered on 17 Feb 2010, 11:08 PM
Thanks!  Looks good.  :-)

Rich
Tags
Editor
Asked by
Travas Nolte
Top achievements
Rank 1
Answers by
Rumen
Telerik team
hacker
Top achievements
Rank 1
Brian Goldman
Top achievements
Rank 2
Richard Buff
Top achievements
Rank 1
Share this question
or