|
Clean Up HTML on the server side
Last post 10-19-2009, 4:26 PM by Adam. 5 replies.
-
09-23-2009, 6:47 PM |
-
Big Kahuna
-
-
-
Joined on 06-03-2009
-
-
Posts 12
-
-
|
Clean Up HTML on the server side
I found these in the help section but when I try to implement them in my code I get the following:
Object doesn't support this property or method: 'CleanUpHTMLCode'
Object doesn't support this property or method: 'CleanUpMicrosoftWordHTML'
You can teach your end users use the Clean Up HTML button () in Cute Editor to remove extraneous tags and streamline your HTML code.
But it's easy to make mistakes if your end users forget Clean Up HTML before saving the content into database.
Cute Editor provides two server side methods which can fix these mistakes automatically and tidy up sloppy editing into nicely layed out markup.
You can use Editor.CleanUpHTMLCode method to remove empty tags, combine nested FONT tags, and otherwise improve messy or unreadable HTML code.
You can aslo Editor.CleanUpMicrosoftWordHTML method to remove the extraneous HTML code generated by Microsoft Word. |
Here's my object:
Dim editor Set editor = New CuteEditor
editor.ID = "event_comments" editor.FilesPath = "/includes/components/CuteEditor_Files" editor.EditorWysiwygModeCss = "/includes/components/CuteEditor_Files/style/text_editor.css" editor.AutoConfigure = "Simple" editor.Width = 733 editor.Height = 500 editor.ThemeType = "office2007" editor.CleanUpHTMLCode = "true" editor.CleanUpMicrosoftWordHTML = "true" editor.UsePhysicalFormattingTags = "true" editor.Text = theComments editor.ImageGalleryPath = thePath editor.FlashGalleryPath = thePath editor.MediaGalleryPath = thePath editor.FilesGalleryPath = thePath editor.TemplateGalleryPath = thePath editor.Draw()
|
|
-
09-24-2009, 10:16 AM |
-
Adam
-
-
-
Joined on 09-23-2003
-
Aurora, ON
-
Posts 18,678
-
-
|
Re: Clean Up HTML on the server side
You can use the following function:
Function CleanUpHTMLCode(HTMLstring)
dim cleanstring set regex = new Regexp
cleanstring=HTMLstring
regex.pattern = "<\\?\??xml[^>]>" regex.ignoreCase = true regex.global = true cleanstring = regex.Replace(cleanstring, "")
regex.pattern = "\s*mso-[^:]+:[^;""]+;?" regex.ignoreCase = true regex.global = true cleanstring = regex.Replace(cleanstring, "")
regex.pattern = "<\/?\w+:[^>]*>" regex.ignoreCase = true regex.global = true cleanstring = regex.Replace(cleanstring, "")
regex.pattern = "<\!--.*-->" regex.ignoreCase = true regex.global = true cleanstring = regex.Replace(cleanstring, "")
regex.pattern = "[\”\“]" regex.ignoreCase = true regex.global = true cleanstring = regex.Replace(cleanstring, """")
regex.pattern = "[\‘\’]" regex.ignoreCase = true regex.global = true cleanstring = regex.Replace(cleanstring, "'")
regex.pattern = "<\\?\?xml[^>]*>" regex.ignoreCase = true regex.global = true cleanstring = regex.Replace(cleanstring, "")
regex.pattern = "<span\s*[^>]*>\s* \s*<\/span>" regex.ignoreCase = true regex.global = true cleanstring = regex.Replace(cleanstring, " ")
regex.pattern = "<span\s*[^>]*><\/span>" regex.ignoreCase = true regex.global = true cleanstring = regex.Replace(cleanstring, "")
regex.pattern = "<(\w+)[^>]*\sstyle=""[^""]*DISPLAY\s?:\s?none(.*?)<\/\1>" regex.ignoreCase = true regex.global = true cleanstring = regex.Replace(cleanstring, "")
CleanUpHTMLCode = cleanstring
set regex = nothing End Function
asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx asp wysiwyg html editor: http://cutesoft.net/ASP asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx Live Support: http://cutesoft.net/live-support/default.aspx
|
|
-
09-24-2009, 10:55 AM |
-
Big Kahuna
-
-
-
Joined on 06-03-2009
-
-
Posts 12
-
-
|
Re: Clean Up HTML on the server side
Thanks but where to I add this function and what about the 'CleanUpMicrosoftWordHTML' option?
|
|
-
09-25-2009, 8:39 AM |
-
10-16-2009, 5:09 PM |
-
ValleyHope
-
-
-
Joined on 06-12-2008
-
-
Posts 19
-
-
|
Re: Clean Up HTML on the server side
is there a way to call the codeCleaner('Word') function instead of calling the CleanCode in the Toolbar.
I tried using your regex function and it still saved a lot of word formatting junk. Surely your codeCleaner function is more robust than the regex function you provided.
Here is my version of the regex function in C#:
- public static string CleanWordHtml(string html)
- {
- String cleanstring = String.Empty;
- System.Text.RegularExpressions.Regex regex;
-
- cleanstring=html;
-
- cleanstring = System.Text.RegularExpressions.Regex.Replace(cleanstring,
- @"<\\?\??xml[^>]>", "",
- System.Text.RegularExpressions.RegexOptions.IgnoreCase);
-
- cleanstring = System.Text.RegularExpressions.Regex.Replace(cleanstring,
- @"\s*mso-[^:]+:[^;""]+;?", "",
- System.Text.RegularExpressions.RegexOptions.IgnoreCase);
-
- cleanstring = System.Text.RegularExpressions.Regex.Replace(cleanstring,
- @"<\/?\w+:[^>]*>", "",
- System.Text.RegularExpressions.RegexOptions.IgnoreCase);
-
- cleanstring = System.Text.RegularExpressions.Regex.Replace(cleanstring,
- @"<\!--.*-->", "",
- System.Text.RegularExpressions.RegexOptions.IgnoreCase);
-
- cleanstring = System.Text.RegularExpressions.Regex.Replace(cleanstring,
- @"[\”\“]", "\"\"",
- System.Text.RegularExpressions.RegexOptions.IgnoreCase);
-
- cleanstring = System.Text.RegularExpressions.Regex.Replace(cleanstring,
- @"[\‘\’]", "'",
- System.Text.RegularExpressions.RegexOptions.IgnoreCase);
-
- cleanstring = System.Text.RegularExpressions.Regex.Replace(cleanstring,
- @"<\\?\?xml[^>]*>", "",
- System.Text.RegularExpressions.RegexOptions.IgnoreCase);
-
- cleanstring = System.Text.RegularExpressions.Regex.Replace(cleanstring,
- @"<span\s*[^>]*>\s* \s*<\/span>", " ",
- System.Text.RegularExpressions.RegexOptions.IgnoreCase);
-
- cleanstring = System.Text.RegularExpressions.Regex.Replace(cleanstring,
- @"<span\s*[^>]*><\/span>", "",
- System.Text.RegularExpressions.RegexOptions.IgnoreCase);
-
- cleanstring = System.Text.RegularExpressions.Regex.Replace(cleanstring,
- @"<(\w+)[^>]*\sstyle=""[^""]*DISPLAY\s?:\s?none(.*?)<\/\1>", "",
- System.Text.RegularExpressions.RegexOptions.IgnoreCase);
-
- return cleanstring;
- }
|
|
-
10-19-2009, 4:26 PM |
-
Adam
-
-
-
Joined on 09-23-2003
-
Aurora, ON
-
Posts 18,678
-
-
|
Re: Clean Up HTML on the server side
ValleyHope:
is there a way to call the codeCleaner('Word') function instead of calling the CleanCode in the Toolbar.
I tried using your regex function and it still saved a lot of word formatting junk. Surely your codeCleaner function is more robust than the regex function you provided.
Here is my version of the regex function in C#:
- public static string CleanWordHtml(string html)
- {
- String cleanstring = String.Empty;
- System.Text.RegularExpressions.Regex regex;
-
- cleanstring=html;
-
- cleanstring = System.Text.RegularExpressions.Regex.Replace(cleanstring,
- @"<\\?\??xml[^>]>", "",
- System.Text.RegularExpressions.RegexOptions.IgnoreCase);
-
- cleanstring = System.Text.RegularExpressions.Regex.Replace(cleanstring,
- @"\s*mso-[^:]+:[^;""]+;?", "",
- System.Text.RegularExpressions.RegexOptions.IgnoreCase);
-
- cleanstring = System.Text.RegularExpressions.Regex.Replace(cleanstring,
- @"<\/?\w+:[^>]*>", "",
- System.Text.RegularExpressions.RegexOptions.IgnoreCase);
-
- cleanstring = System.Text.RegularExpressions.Regex.Replace(cleanstring,
- @"<\!--.*-->", "",
- System.Text.RegularExpressions.RegexOptions.IgnoreCase);
-
- cleanstring = System.Text.RegularExpressions.Regex.Replace(cleanstring,
- @"[\”\“]", "\"\"",
- System.Text.RegularExpressions.RegexOptions.IgnoreCase);
-
- cleanstring = System.Text.RegularExpressions.Regex.Replace(cleanstring,
- @"[\‘\’]", "'",
- System.Text.RegularExpressions.RegexOptions.IgnoreCase);
-
- cleanstring = System.Text.RegularExpressions.Regex.Replace(cleanstring,
- @"<\\?\?xml[^>]*>", "",
- System.Text.RegularExpressions.RegexOptions.IgnoreCase);
-
- cleanstring = System.Text.RegularExpressions.Regex.Replace(cleanstring,
- @"<span\s*[^>]*>\s* \s*<\/span>", " ",
- System.Text.RegularExpressions.RegexOptions.IgnoreCase);
-
- cleanstring = System.Text.RegularExpressions.Regex.Replace(cleanstring,
- @"<span\s*[^>]*><\/span>", "",
- System.Text.RegularExpressions.RegexOptions.IgnoreCase);
-
- cleanstring = System.Text.RegularExpressions.Regex.Replace(cleanstring,
- @"<(\w+)[^>]*\sstyle=""[^""]*DISPLAY\s?:\s?none(.*?)<\/\1>", "",
- System.Text.RegularExpressions.RegexOptions.IgnoreCase);
-
- return cleanstring;
- }
If you are using .net version, you can use the following method:
Editor.CleanUpMicrosoftWordHTML Method
Use the Clean Up Word HTML function to remove the extraneous HTML code generated by Microsoft Word.
asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx asp wysiwyg html editor: http://cutesoft.net/ASP asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx Live Support: http://cutesoft.net/live-support/default.aspx
|
|
|
|
|