A COM Wrapper for HTML Tidy
Author: André BlavierUnfortunately, I am no longer able to maintain TidyGUI and TidyCOM. However,
notice that the HTML Tidy core software is still well alive (see the
Tidy Source Forge project).
TidyGUI and TidyCOM (based on the 4th August 2000 version of HTML Tidy) will still
be available from this site as long as necessary. If anybody is willing to continue
the development of these programs, feel free to do so--all source code is available.
Many many thanks to the numerous folks who helped me improve the programs with their
suggestions, bug reports and friendly messages.
TidyCOM is a Windows COM component wrapping Dave Raggett's HTML Tidy, a free utility application from the World Wide Web Consortium that helps you clean up your web pages.
HTML Tidy is available from the W3C as a command-line program, à la Unix. To better fit in the Windows environment I have written a GUI front-end for Tidy called TidyGUI and a COM component wrapper for Tidy available here.
Current version (1.2.6, 27 June 2001) is based on the 4th August 2000 version of HTML Tidy.
TidyCOM exposes the TidyObject COM class (with interface
ITidyObject). Through the Options property
you can access the TidyOptions class (with interface
ITidyOptions). The TidyOptions class
allows you to change every Tidy option setting (but write-back).
Here's how you could use TidyCOM in VBScript:
Set TidyObj = CreateObject("TidyCOM.TidyObject")
TidyObj.Options.Doctype = "strict"
TidyObj.Options.DropFontTags = true
TidyObj.Options.OutputXhtml = true
TidyObj.Options.Indent = 2 'AutoIndent
TidyObj.Options.TabSize = 8
TidyObj.TidyToFile "bad.html", "good.html"
Or you could simply load a Tidy configuration file:
Set TidyObj = CreateObject("TidyCOM.TidyObject")
TidyObj.Options.Load "myconfig.txt"
TidyObj.TidyToFile "bad.html", "good.html"
Both interfaces are dual interfaces, so TidyCOM can be used from scripting languages and from compiled languages alike.
Warning: TidyCOM's code is not re-entrant--no
more than 1 instance of TidyObject should be
alive at the same time in the same process.
ITidyObject InterfaceTidyToMem(sourceFile) -
invokes Tidy on sourceFile. Returns tidied file content
as a string.TidyToFile(sourceFile,
destFile) -
invokes Tidy on sourceFile and writes tidied content
in destFile (sourceFile
can be the same file name as destFile).TidyMemToMem(sourceString) -
invokes Tidy with sourceString. Returns tidied string content
as a string. (Actually uses a temporary file.)Options (read-only property) - yields access to the
TidyOptions class.TotalWarnings (read-only integer property) - number of
warning messages from Tidy.Warning(i)
(read-only string property) - ith warning message from Tidy
(0-based).TotalErrors (read-only integer property) - number of
error messages from Tidy.Error(i)
(read-only string property) - ith error message from Tidy
(0-based).Comments (read-only string property) - comments generated
by Tidy.ITidyOptions InterfaceLoad(configFile) -
load option settings from configFileReset() -
reset options to default settingsFurthermore, there is a read-write property for each option that can be used in configuration
files (only write-back is missing - you can achieve its effect with
TidyToFile(sourceFile,
sourceFile)).
See the complete list of option properties.
TidyGUI is supposed to work on all Win32 versions of Windows. It has been tested on Windows 95 and NT4.
TidyMemToMem(sourceString)
changed again--it should now work on all Win32 platforms, whatever the
input string's size. Special thanks to Greg Clouston for his kind help.TidyMemToMem(sourceString)
causing trouble with large files.Markup option logic
(thanks to Andrew Kidd for this one).clean!) to have no effect (thanks to Mark Carrington who found that bug).Three steps are required to install TidyCOM:
TidyCOM.dll) and a utility program to register the
component (regsvr32.exe).regsvr32 <full_pathname_of_TidyCOM.dll> -
to unregister, type: regsvr32 /u <full_pathname_of_TidyCOM.dll>)Source code is available here (.zip file--also contains source code of TidyGUI). TidyCOM was developped with Visual C++ 6.0 and the ATL library.
You can use, copy, modify and distribute TidyCOM and its source code without fee. However:
tidy.c).