program htmlwalk;


{  Example of how to traverse the document tree. Input from filename or stdin. }


{$IFDEF FPC}{$H+}{$MODE OBJFPC}{$ENDIF}
{$IFDEF WIN32}{$APPTYPE CONSOLE}{$ENDIF}

uses tidyobj;


function Indent(n:LongInt):string;
begin
  Result:=StringOfChar(' ', n*2);
end;

procedure MyNodeProc(const info:tNodeInfo; data:pointer);
begin
  if ( info.StartTag <> nil ) 
  then WriteLn(Indent(info.Level), info.StartTag)   // Write out the opening tag 
  else if ( info.Text <> nil ) then WriteLn(info.Text);   // or text
  ForEachNode(info.Doc, info.Child, @MyNodeProc, data);   // Recurse into the child nodes
  if ( info.EndTag <> nil ) then WriteLn(Indent(info.Level), info.EndTag);  // Close the tag
end;


var
  Tidy:tTidy;
begin
  Tidy:=tTidy.Create(nil);
  Tidy.WrapLen:=32767;
  Tidy.ForceOutput:=True;
  Tidy.UpperCaseTags:=True;
  Tidy.OutputMode:=omAuto;
  Tidy.PreScanScripts:=True;
  Tidy.AllowUnknownTags:=True;
  Tidy.MergeOrphanForms:=True;
  if ( ParamCount = 0 ) then WriteLn(ErrOutput, 'Parsing console input...' );
  if ( Tidy.ParseFile(ParamStr(1)) <> '' ) 
  then ForEachNode(Tidy.Handle, Tidy.RootNode, @MyNodeProc, nil);
  Tidy.Free;
end.



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