home *** CD-ROM | disk | FTP | other *** search
- unit HtmlTool;
-
- interface
-
- uses Classes, SysUtils, ComCtrls;
-
- { file based }
- procedure HtmlHeader(var AFile: TextFile; ATitle: string; const S: array of shortstring);
- procedure HtmlFooter(var AFile: TextFile; const S: array of shortstring);
- procedure HtmlOutline(var AFile: TextFile; Tree: TTreeView);
-
- { Miscellaneous }
- function DosToUnixPath(const Path: string): string;
- function UnixToDosPath(const Path: string): string;
- function RelToAbsPath(Ref, Path: string): string;
- function AbsToRelPath(Ref, Path: string): string;
-
- implementation
-
- { file based }
- procedure HtmlHeader(var AFile: TextFile; ATitle: string; const S: array of shortstring);
- var
- i: integer;
- begin
- { write Html header }
- Writeln(AFile, '<HTML>');
- Writeln(AFile, '<HEAD><TITLE> ');
- Writeln(AFile, ATitle);
- Writeln(AFile, '</TITLE>');
- for i := 0 to High(S) do
- begin
- Write(AFile, '<META> ');
- Writeln(AFile, S[i]);
- end;
- Writeln(AFile, '</HEAD>');
- end;
-
- procedure HtmlFooter(var AFile: TextFile; const S: array of shortstring);
- var
- i: integer;
- begin
- { Html footer }
- Writeln(AFile, '<HR>');
- for i := 0 to High(S) do
- Writeln(AFile, S[i]);
- Writeln(AFile, '</BODY></HTML>');
- end;
-
- procedure HtmlOutline(var AFile: TextFile; Tree: TTreeView);
- var
- i, j: integer;
- CurLev: word;
- begin
- CurLev := 0;
- { iterate through the outline }
- for i := 0 to Tree.Items.Count-1 do
- begin
- { if Node is visible }
- if Tree.Items[i].IsVisible then
- begin
- { if level goes up... }
- if Tree.Items[i].Level > CurLev then
- begin
- Write(AFile, '<UL>'); { increase indent }
- Inc(CurLev); { increase CurLev }
- end;
- { if level goes down... }
- if Tree.Items[i].Level < CurLev then
- { for CurLev down to the new level }
- for j := CurLev downto Tree.Items[i].Level+1 do
- begin
- Write(AFile, '</UL>'); { close list level }
- Dec(CurLev); { decrease CurLev }
- end;
- Write(AFile, '<LI>');
- Write(AFile, Tree.Items[i].Text); { write out the actual text }
- Writeln(AFile, '</A>')
- end;
- end;
- for j := CurLev downto 0 do Writeln(AFile, '</UL>'); { close all list levels }
- end;
-
- { Miscellaneous }
- function TranslateChar(const Str: string; FromChar, ToChar: Char): string;
- var
- I: Integer;
- begin
- Result := Str;
- for I := 1 to Length(Result) do
- if Result[I] = FromChar then
- Result[I] := ToChar;
- end;
-
- function DosToUnixPath(const Path: string): string;
- begin
- Result := TranslateChar(Path, '\', '/');
- end;
-
- function UnixToDosPath(const Path: string): string;
- begin
- Result := TranslateChar(Path, '/', '\');
- end;
-
-
- function RelToAbsPath(Ref, Path: string): string;
- begin
- try
- ChDir(Ref);
- Result := ExpandFileName(Path);
- except
- Result := Path;
- end;
- end;
-
- function AbsToRelPath(Ref, Path: string): string;
- begin
- Result := ExtractRelativePath(Ref, Path);
- end;
-
- end.
-