Hello!
Pasting text through the "Paste Text From Word" removes unwanted style definitions and works as expected. However my users are quite reluctant to use this button and they usually just paste via CTRL+V.
Is there any method to filter out unwanted stylings when text is pasted via keyboard shortcuts?
Pasting text through the "Paste Text From Word" removes unwanted style definitions and works as expected. However my users are quite reluctant to use this button and they usually just paste via CTRL+V.
Is there any method to filter out unwanted stylings when text is pasted via keyboard shortcuts?

Re: Automatically remove style attributes on paste
http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/Configuration/Configuration_Options
Re: Automatically remove style attributes on paste
Re: Automatically remove style attributes on paste
Re: Automatically remove style attributes on paste
The dialog "paste from word" works great, however I want theses filters applied even when text is pasted via keyboard shortcuts.
Re: Automatically remove style attributes on paste
If this is something you would like to look into, then I will see if I can find the link.
Re: Automatically remove style attributes on paste
Re: Automatically remove style attributes on paste
I cannot find it, but here is the code. I cannot give the person credit because I don't know who it is. Also, I made small changes that should speed it up a bit.
I removed our stuff from it, so it might not build, just check namespaces/braces etc.
using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Collections.Specialized; using System.Text.RegularExpressions; using System.Collections; namespace YOURNAMESPACE { public static class WordCleaner { public static void Clean(string filename) { if (string.IsNullOrEmpty(filename)) { throw new ArgumentNullException("No filename provided."); } string filepath = filename; if (Path.GetFileName(filepath) == filename) { filepath = @"C:\temp\convertdocs\";//Path.Combine(Environment.CurrentDirectory, filepath); } if (!File.Exists(filename)) { throw new FileNotFoundException("File doesn't exist."); } string html = File.ReadAllText(filepath); Console.WriteLine("input html is " + html.Length + " chars"); html = CleanWordHtml(html); html = FixEntities(html); filepath = Path.GetFileNameWithoutExtension(filepath) + ".modified.htm"; File.WriteAllText(filepath, html); Console.WriteLine("cleaned html is " + html.Length + " chars"); } public static string CleanWordHtml(string html) { StringCollection sc = new StringCollection(); // get rid of unnecessary tag spans (comments and title) sc.Add(@"<!--(\w|\W)+?-->"); sc.Add(@"<title>(\w|\W)+?</title>"); // Get rid of classes and styles sc.Add(@"\s?class=\w+"); sc.Add(@"\s+style='[^']+'"); // Get rid of unnecessary tags sc.Add( @"<(meta|link|/?o:|/?style|/?div|/?st\d|/?head|/?html|body|/?body|/?span|!\[)[^>]*?>"); // Get rid of empty paragraph tags sc.Add(@"(<[^>]+>)+ (</\w+>)+"); // remove bizarre v: element attached to <img> tag sc.Add(@"\s+v:\w+=""[^""]+"""); // remove extra lines sc.Add(@"(\n\r){2,}"); foreach (string s in sc) { html = Regex.Replace(html, s, "", RegexOptions.IgnoreCase); } return FixEntities(html); } public static string FixEntities(string html) { Hashtable nvc = new Hashtable(); nvc.Add("“", "“"); nvc.Add("”", "”"); nvc.Add("–", "—"); foreach (string key in nvc.Keys) { html = html.Replace(key, nvc[key].ToString()); } return html; } } }Then you use it
The extra method for cleaning out files is there as well...not sure if that still works since we don't use it any more.