I have a WYSIWYG editor visitors use to create blog posts. Often they use this to cut content from other sources, like MS Word or another web page, and paste the content into the WYSIWYG.

When they cut & paste their content, it brings with it a whole mess of additional formatting, skewing the post content.

I could strip all formatting from the posted content on the server side, but this would defeat the purpose of having a WYSIWYG.

The best option I can think of is to use javascript/jQuery to strip the formatting before the post is submitted. I would likely use keyUp() and keyDown() for this.

Step 1: Save cursor position upon keyDown()

Step 2: Save cursor position upon keyUp()

Step 3: Use regex to strip formatting from everything between keyUp and keyDown.

This would allow me to operate exclusively on the freshly pasted content while keeping the formatting the user has previously created via the WYSIWYG.

I have a few questions. Most importantly, does this sound like the most practical solution? I'm not even sure yet if keyUp() will register the cursor position as being before or after the pasted content.

Also, which jQuery/javascript function captures the cursor position?

Finally, this is for a Wordpress site. If anyone knows of a plugin that already addresses this problem, please let me know.