HTML Tidy  5.4.0
The HTACG Tidy HTML Project
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Basic Operations

Detailed Description

Tidy public interface.

Several functions return an integer document status:

   0    -> SUCCESS
   >0   -> 1 == TIDY WARNING, 2 == TIDY ERROR
   <0   -> SEVERE ERROR
   

The following is a short example program.

#include <tidy.h>
#include <tidybuffio.h>
#include <stdio.h>
#include <errno.h>
int main(int argc, char **argv )
{
  const char* input = "&lt;title&gt;Foo&lt;/title&gt;&lt;p&gt;Foo!";
  TidyBuffer output;
  TidyBuffer errbuf;
  int rc = -1;
  Bool ok;
  TidyDoc tdoc = tidyCreate();                     // Initialize "document"
  tidyBufInit( &output );
  tidyBufInit( &errbuf );
  printf( "Tidying:\t\%s\\n", input );
  ok = tidyOptSetBool( tdoc, TidyXhtmlOut, yes );  // Convert to XHTML
  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;
}

Functions

uint TIDY_CALL tidyAccessWarningCount (TidyDoc tdoc)
 Number of Tidy accessibility warnings encountered. More...
 
uint TIDY_CALL tidyConfigErrorCount (TidyDoc tdoc)
 Number of Tidy configuration errors encountered. More...
 
TidyDoc TIDY_CALL tidyCreate (void)
 The primary creation of a TidyDoc. More...
 
TidyDoc TIDY_CALL tidyCreateWithAllocator (TidyAllocator *allocator)
 Create a Tidoc supplying the TidyAllocator. More...
 
Bool TIDY_CALL tidyDetectedGenericXml (TidyDoc tdoc)
 Input is generic XML (not HTML or XHTML)? More...
 
int TIDY_CALL tidyDetectedHtmlVersion (TidyDoc tdoc)
 Detected HTML version: 0, 2, 3 or 4. More...
 
Bool TIDY_CALL tidyDetectedXhtml (TidyDoc tdoc)
 Input is XHTML? More...
 
uint TIDY_CALL tidyErrorCount (TidyDoc tdoc)
 Number of Tidy errors encountered. More...
 
void TIDY_CALL tidyErrorSummary (TidyDoc tdoc)
 Write more complete information about errors to current error sink. More...
 
Bool TIDY_CALL tidyFileExists (TidyDoc tdoc, ctmbstr filename)
 
void TIDY_CALL tidyGeneralInfo (TidyDoc tdoc)
 Write more general information about markup to current error sink. More...
 
void *TIDY_CALL tidyGetAppData (TidyDoc tdoc)
 Get application data set previously. More...
 
ctmbstr TIDY_CALL tidyLibraryVersion (void)
 Get version number for the current library. More...
 
int TIDY_CALL tidyLoadConfig (TidyDoc tdoc, ctmbstr configFile)
 Load an ASCII Tidy configuration file. More...
 
int TIDY_CALL tidyLoadConfigEnc (TidyDoc tdoc, ctmbstr configFile, ctmbstr charenc)
 Load a Tidy configuration file with the specified character encoding. More...
 
int TIDY_CALL tidyOptSaveFile (TidyDoc tdoc, ctmbstr cfgfil)
 Save current settings to named file. More...
 
int TIDY_CALL tidyOptSaveSink (TidyDoc tdoc, TidyOutputSink *sink)
 Save current settings to given output sink. More...
 
void TIDY_CALL tidyRelease (TidyDoc tdoc)
 Free all memory and release the TidyDoc. More...
 
ctmbstr TIDY_CALL tidyReleaseDate (void)
 Get release date (version) for current library. More...
 
void TIDY_CALL tidySetAppData (TidyDoc tdoc, void *appData)
 Let application store a chunk of data w/ each Tidy instance. More...
 
int TIDY_CALL tidySetCharEncoding (TidyDoc tdoc, ctmbstr encnam)
 Set the input/output character encoding for parsing markup. More...
 
int TIDY_CALL tidySetInCharEncoding (TidyDoc tdoc, ctmbstr encnam)
 Set the input encoding for parsing markup. More...
 
int TIDY_CALL tidySetOutCharEncoding (TidyDoc tdoc, ctmbstr encnam)
 Set the output encoding. More...
 
int TIDY_CALL tidyStatus (TidyDoc tdoc)
 Get status of current document. More...
 
uint TIDY_CALL tidyWarningCount (TidyDoc tdoc)
 Number of Tidy warnings encountered. More...
 

Function Documentation

uint TIDY_CALL tidyAccessWarningCount ( TidyDoc  tdoc)

Number of Tidy accessibility warnings encountered.

uint TIDY_CALL tidyConfigErrorCount ( TidyDoc  tdoc)

Number of Tidy configuration errors encountered.

TidyDoc TIDY_CALL tidyCreate ( void  )

The primary creation of a TidyDoc.

This must be the first call before most of the Tidy API which require the TidyDoc parameter. When completed tidyRelease( TidyDoc tdoc ); should be called to release all memory

TidyDoc TIDY_CALL tidyCreateWithAllocator ( TidyAllocator *  allocator)

Create a Tidoc supplying the TidyAllocator.

See the TidyAllocator structure for creating an allocator

Bool TIDY_CALL tidyDetectedGenericXml ( TidyDoc  tdoc)

Input is generic XML (not HTML or XHTML)?

int TIDY_CALL tidyDetectedHtmlVersion ( TidyDoc  tdoc)

Detected HTML version: 0, 2, 3 or 4.

Bool TIDY_CALL tidyDetectedXhtml ( TidyDoc  tdoc)

Input is XHTML?

uint TIDY_CALL tidyErrorCount ( TidyDoc  tdoc)

Number of Tidy errors encountered.

If > 0, output is suppressed unless TidyForceOutput is set.

void TIDY_CALL tidyErrorSummary ( TidyDoc  tdoc)

Write more complete information about errors to current error sink.

Bool TIDY_CALL tidyFileExists ( TidyDoc  tdoc,
ctmbstr  filename 
)
void TIDY_CALL tidyGeneralInfo ( TidyDoc  tdoc)

Write more general information about markup to current error sink.

void* TIDY_CALL tidyGetAppData ( TidyDoc  tdoc)

Get application data set previously.

ctmbstr TIDY_CALL tidyLibraryVersion ( void  )

Get version number for the current library.

int TIDY_CALL tidyLoadConfig ( TidyDoc  tdoc,
ctmbstr  configFile 
)

Load an ASCII Tidy configuration file.

int TIDY_CALL tidyLoadConfigEnc ( TidyDoc  tdoc,
ctmbstr  configFile,
ctmbstr  charenc 
)

Load a Tidy configuration file with the specified character encoding.

int TIDY_CALL tidyOptSaveFile ( TidyDoc  tdoc,
ctmbstr  cfgfil 
)

Save current settings to named file.

Only non-default values are written.

int TIDY_CALL tidyOptSaveSink ( TidyDoc  tdoc,
TidyOutputSink sink 
)

Save current settings to given output sink.

Only non-default values are written.

void TIDY_CALL tidyRelease ( TidyDoc  tdoc)

Free all memory and release the TidyDoc.

TidyDoc can not be used after this call.

ctmbstr TIDY_CALL tidyReleaseDate ( void  )

Get release date (version) for current library.

Deprecated:
tidyReleaseDate() is deprecated in favor of semantic versioning and should be replaced with tidyLibraryVersion().
void TIDY_CALL tidySetAppData ( TidyDoc  tdoc,
void *  appData 
)

Let application store a chunk of data w/ each Tidy instance.

Useful for callbacks.

int TIDY_CALL tidySetCharEncoding ( TidyDoc  tdoc,
ctmbstr  encnam 
)

Set the input/output character encoding for parsing markup.

Values include: ascii, latin1, raw, utf8, iso2022, mac, win1252, utf16le, utf16be, utf16, big5 and shiftjis. Case in-sensitive.

int TIDY_CALL tidySetInCharEncoding ( TidyDoc  tdoc,
ctmbstr  encnam 
)

Set the input encoding for parsing markup.

As for tidySetCharEncoding but only affects the input encoding

int TIDY_CALL tidySetOutCharEncoding ( TidyDoc  tdoc,
ctmbstr  encnam 
)

Set the output encoding.

int TIDY_CALL tidyStatus ( TidyDoc  tdoc)

Get status of current document.

uint TIDY_CALL tidyWarningCount ( TidyDoc  tdoc)

Number of Tidy warnings encountered.