World!"; + TidyBuffer output = {0}; + TidyBuffer errbuf = {0}; + int rc = -1; + Bool ok; + + // Initialize "document" + TidyDoc tdoc = tidyCreate(); + printf( "Tidying:\t%s\n", input ); + + // Convert to XHTML + ok = tidyOptSetBool( tdoc, TidyXhtmlOut, yes ); + if ( ok ) + rc = tidySetErrorBuffer( tdoc, &errbuf ); // Capture diagnostics + if ( rc >= 0 ) + rc = tidyParseString( tdoc, input ); // Parse the input + if ( rc >= 0 ) + rc = tidyCleanAndRepair( tdoc ); // Tidy it up! + if ( rc >= 0 ) + rc = tidyRunDiagnostics( tdoc ); // Kvetch + if ( rc > 1 ) // If error, force output. + rc = ( tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1 ); + if ( rc >= 0 ) + rc = tidySaveBuffer( tdoc, &output ); // Pretty Print + + if ( rc >= 0 ) + { + if ( rc > 0 ) + printf( "\nDiagnostics:\n\n%s", errbuf.bp ); + printf( "\nAnd here is the result:\n\n%s", output.bp ); + } + else + printf( "A severe error (%d) occurred.\n", rc ); + + tidyBufFree( &output ); + tidyBufFree( &errbuf ); + tidyRelease( tdoc ); + return rc; +} + diff --git a/build/documentation/tidy_docs.dox b/build/documentation/tidy_docs.dox new file mode 100644 index 0000000..2f7968f --- /dev/null +++ b/build/documentation/tidy_docs.dox @@ -0,0 +1,164 @@ +/*! + +\mainpage Tidy home + +\note The repository github.com/htacg/tidy-html5 and this documentation should be considered canonical for HTML Tidy as of 2015-January-15. + +
+\htmlinclude tidy5.cmd.txt ++ +\page TidyLib TidyLib + +- \b TidyLib - is easy to integrate. Because of the near universal adoption of C linkage, a C interface may be called from a great number of programming languages. + +- \b TidyLib - is designed to use opaque types in the public interface. This allows the application to just pass an integer around and the need to transform data types in different languages is minimized. As a results it’s straight-forward to write very thin library wrappers for C++, Pascal, and COM/ATL. + +- \b TidyLib - eats its own dogfood. HTML Tidy links directly to TidyLib. + +- \b TidyLib - is Thread Safe and Re-entrant. Because there are many uses for HTML Tidy - from content validation, content scraping, conversion to XHTML - it was important to make TidyLib run reasonably well within server applications as well as client side. + +- \b TidyLib - uses adaptable I/O. As part of the larger integration strategy it was decided to fully abstract all I/O. This means a (relatively) clean separation between character encoding processing and shovelling bytes back and forth. Internally, the library reads from sources and writes to sinks. This abstraction is used for both markup and configuration “files”. Concrete implementations are provided for file and memory I/O, and new sources and sinks may be provided via the public interface. + +\section example_hello Example + +\include example.1.c + + +\page building_tidy Building Tidy + +\section Prerequisites + + - \b git - git-scm.com/book/en/v2/Getting-Started-Installing-Git + - \b cmake - cmake.org/download/ + - Appropriate build tools for the platform + +CMake comes in two forms - command line and gui. Some installations only install one or the other, but sometimes both. The build +commands below are only for the command line use. + +Also the actual build tools vary for each platform. But that is one of the great features of cmake, it can generate +variuous 'native' build files. Running cmake without any parameters will list the generators +available on that platform. For sure one of the common ones is "Unix Makefiles", which needs autotools +make installed, but many other generators are supported. + +In windows cmake offers various versions of MSVC. Again below only the command line use of MSVC is shown, but the +tidy solution (*.sln) file can be loaded into the MSVC IDE, and the building done in there. + +\section get_source Get the source code + +Tidy’s sourcecode can be found at github.com/htacg/tidy-html5. There are sometimes +several branches, but in general `master` is the most recently updated version. + +\note Note that as “cutting edge,” it may have bugs or other +unstable behavior. If you prefer a stable, officially released version, be sure to have a look +at Releases on the github page. + +In general you can use the Download ZIP button on the github page to download the most recent version of a branch. If you prefer +Git then you can clone the repository to a working machine with: + + +\code{.sh} +git clone git@github.com:htacg/tidy-html5.git +\endcode + +\section compile Compile + +
HTML Tidy was created by the W3C’s own Dave Raggett back in the +dawn of the Internet age. His original Internet page is still available and +gives a sense of the early history: Clean up your Web pages with HTML TIDY.
+ +Satisfied with his work Dave passed the torch to a dedicated group of +maintainers at tidy.sourceforge.net where the important tasks of turning +Tidy into a C library and keeping up with developing standards was +performed.
+ +W3C members took a renewed interest in Tidy in 2011 and forked the +project to github (now redirects to new maintainers), where it featured +compatibility with HTML5 via a key contribution from one of the SourceForge +key members.
+ +In 2015 a group of concerned developers, users, and software integrators formed +HTACG with the goal of revitalizing Tidy, which had fallen into a +non-maintained state. As a W3C Community Group, HTACG was deemed worthy by the +W3C, and W3C passed ownership of their project to HTACG, where it is currently +being developed and prepped for a new, stable, and modern release.
+ +HTACG is also working diligently with the SourceForge maintainers in an effort +to harmonize HTML Tidy into a single, stable, solid release once again.
+ +*/ diff --git a/include/tidy.h b/include/tidy.h index 87d5453..945d38b 100755 --- a/include/tidy.h +++ b/include/tidy.h @@ -160,7 +160,7 @@ struct _TidyAllocator; /** The allocator **/ typedef struct _TidyAllocator TidyAllocator; -/** An allocator's function table. All functions here must +/** An allocator's function table. All functions here must be provided. */ struct _TidyAllocatorVtbl { @@ -187,7 +187,7 @@ struct _TidyAllocatorVtbl { /** An allocator. To create your own allocator, do something like the following: - + \code typedef struct _MyAllocator { TidyAllocator base; ...other custom allocator state... @@ -213,7 +213,7 @@ struct _TidyAllocatorVtbl { allocator.base.vtbl = &MyAllocatorVtbl; ...initialise allocator specific state... doc = tidyCreateWithAllocator(&allocator); - ... + \endcode Although this looks slightly long winded, the advantage is that to create a custom allocator you simply need to set the vtbl pointer correctly. @@ -261,10 +261,10 @@ TIDY_EXPORT Bool TIDY_CALL tidySetPanicCall( TidyPanic fpanic ); The following is a short example program.-#include <tidy.h> -#include <buffio.h> -#include <stdio.h> -#include <errno.h> +\#include <tidy.h> +\#include <buffio.h> +\#include <stdio.h> +\#include <errno.h> int main(int argc, char **argv )