2

I have created a WYSIWYG HTML editor and I noticed that when you paste text from Word, it comes in with its source formatting and I don't want it. Is it possible to clean that up when it gets to the editor.

What I need the most is being able to clean-up the text before it get to the editor itself. Something like an "onPaste" thing that can allow me to filter my text when it's pasted (using the command or keyboard shortcut).

Lightness Races in Orbit
  • 358,771
  • 68
  • 593
  • 989
Sthe
  • 2,388
  • 2
  • 27
  • 45
  • Could you give a sample of the resulting text when you paste from Word into your editor? I might still be unable to help, but as I don't use Windows I'm unable even to try and work that out, currently. – David says reinstate Monica Jan 01 '12 at 15:19
  • Please don't sign posts. – Lightness Races in Orbit Jan 08 '12 at 19:52
  • There is a `paste` event listener you can use. It is called on any type of 'paste' action and allows you to cancel the paste. I'm actually working on a WYSIWYG right now, but am just flagging the content for cleanup and altering the DOM after the paste (in contenteditable div), rather than fixing it before the paste. – 0b10011 Jan 08 '12 at 19:55
  • linked - [get clipboard data on paste event](https://stackoverflow.com/q/2176861/104380) – vsync May 01 '20 at 19:07

1 Answers1

4

HTML Purifier will create standards compliant markup http://htmlpurifier.org/ Or http://www.w3.org/People/Raggett/tidy/

If those don't help you, I suggest you switch to FCKEditor or tinymce which has this feature built-in.

Dominic Green
  • 9,716
  • 4
  • 27
  • 34