program libdemo;

{

  Basic example of using the libtidy bindings directly.

  Writes the string "Hello World" in HTML 
  ( Adapted from the C example in "tidy.h" )

}


{$H+}

{$IFDEF WIN32}{$APPTYPE CONSOLE}{$ENDIF}

uses tidy_h;


var
  Source :pChar = '<title>Hello World<p>Hello World';
  ResultCode:LongInt = -1;
  TidyHandle:pTidyDoc;
  Target:tTidyBuffer;
  ErrorBuffer: tTidyBuffer;


begin
  TidyHandle := tidyCreate();
  WriteLn;
  WriteLn( 'Tidying: "', Source, '"' );
  if ( not tidyOptSetBool( TidyHandle, TidyXhtmlOut, True ) ) then begin
    WriteLn('Error setting TidyLib option: "TidyXhtmlOut"');
    HALT(1);
  end;
  ResultCode := tidySetErrorBuffer( TidyHandle, @ErrorBuffer );
  if ( ResultCode >= 0 ) then ResultCode := tidyParseString( TidyHandle, ctmbstr(Source) );
  if ( ResultCode >= 0 ) then ResultCode := tidyCleanAndRepair( TidyHandle );
  if ( ResultCode >= 0 ) then ResultCode := tidyRunDiagnostics( TidyHandle );
  if ( ResultCode > 1  ) then begin
    if ( not tidyOptSetBool(TidyHandle, TidyForceOutput, True ) ) then begin 
      WriteLn('Error setting TidyLib option: "TidyForceOutput"');
      HALT(1);
    end;
  end;
  if ( ResultCode >= 0 ) then ResultCode := tidySaveBuffer( TidyHandle, @Target );
  if ( ResultCode >= 0 ) then begin
    if ( ResultCode > 0 ) then begin
      WriteLn('Diagnostics:');
      WriteLn(pChar(ErrorBuffer.bp) );
    end;
    WriteLn( 'And here is the result:');
    WriteLn( pChar(Target.bp) );
  end else WriteLn( 'A severe error (', ResultCode, ') occurred: ');
  tidyBufFree( @Target );
  tidyBufFree( @ErrorBuffer );
  tidyRelease( TidyHandle );
  HALT(byte(ResultCode));
end.




Get CurlPas and TidyPas at SourceForge.net. Fast, secure and Free Open Source software downloads