2 #include <tidybuffio.h>
6 int main(int argc, char **argv )
8 const char* input = "<title>Foo</title><p>Foo!";
9 TidyBuffer output = {0};
10 TidyBuffer errbuf = {0};
14 TidyDoc tdoc = tidyCreate(); // Initialize "document"
15 printf( "Tidying:\t%s\n", input );
17 ok = tidyOptSetBool( tdoc, TidyXhtmlOut, yes ); // Convert to XHTML
19 rc = tidySetErrorBuffer( tdoc, &errbuf ); // Capture diagnostics
21 rc = tidyParseString( tdoc, input ); // Parse the input
23 rc = tidyCleanAndRepair( tdoc ); // Tidy it up!
25 rc = tidyRunDiagnostics( tdoc ); // Kvetch
26 if ( rc > 1 ) // If error, force output.
27 rc = ( tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1 );
29 rc = tidySaveBuffer( tdoc, &output ); // Pretty Print
34 printf( "\nDiagnostics:\n\n%s", errbuf.bp );
35 printf( "\nAnd here is the result:\n\n%s", output.bp );
38 printf( "A severe error (%d) occurred.\n", rc );
40 tidyBufFree( &output );
41 tidyBufFree( &errbuf );