📄 convert.pas
字号:
AppendStr (OutStr, '<B>');
end;
procedure THtmlParser.AfterKeyword;
begin
AppendStr (OutStr, '</B>');
end;
procedure THtmlParser.BeforeString;
begin
// no special style...
end;
procedure THtmlParser.AfterString;
begin
// no special style...
end;
function THtmlParser.CheckSpecialToken (Ch1: char): string;
begin
case Ch1 of
'<': Result := '<';
'>': Result := '>';
'&': Result := '&';
'"': Result := '"';
else
Result := Ch1;
end;
end;
procedure THtmlParser.AddFileHeader (FileName: string);
var
FName: string;
begin
FName := Uppercase (ExtractFilename (FileName));
AppendStr (OutStr, Format (
'<A NAME=%s><H3>%s</H3></A>' + #13#10 + #13#10,
[FName, FName]));
end;
class function THtmlParser.HtmlHead (Filename: string): string;
begin
Result := '<HTML><HEAD>' + #13#10 +
'<TITLE>File: ' + ExtractFileName(Filename) + '</TITLE>' + #13#10 +
'<META NAME="GENERATOR" CONTENT="PasToWeb[Marco Cant鵠">'#13#10 +
'</HEAD>'#13#10 +
'<BODY BGCOLOR="#FFFFFF">'#13#10;
end;
class function THtmlParser.HtmlTail (Copyright: string): string;
begin
Result := '<HR><CENTER<I>Generated by PasToWeb,' +
' a tool by Marco Cantù.<P>' + #13#10 +
Copyright + '</CENTER></I>'#13#10 + '</BODY> </HTML>';
end;
// code for the HTML Wizard
function OpenProjectToHTML (Filename, Copyright: string): string;
begin
// open the project and get the lists...
ToolServices.OpenProject (FileName);
Result := CurrProjectToHTML (Copyright);
end;
function CurrProjectToHTML (Copyright: string): string;
var
Dest, Source, BinSource: TStream;
HTML, FileName, Ext, FName: string;
I: Integer;
Parser: THtmlParser;
begin
// initialize
FileName := ToolServices.GetProjectName;
Result := ChangeFileExt (FileName, '_dpr') + '.htm';
Dest := TFileStream.Create (Result,
fmCreate or fmOpenWrite);
try
// add head
HTML := '<HTML><HEAD>' + #13#10 +
'<TITLE>Project: ' + ExtractFileName (Filename) +
'</TITLE>' + #13#10 +
'<META NAME="GENERATOR" CONTENT="PasToHTML[Marco Cant鵠">' + #13#10 +
'</HEAD>'#13#10 +
'<BODY BGCOLOR="#FFFFFF">'#13#10 +
'<H1><CENTER>Project: ' + FileName +
'</CENTER></H1><BR><BR><HR>'#13#10;
AppendStr (HTML, '<UL>'#13#10);
// units list
for I := 0 to ToolServices.GetUnitCount - 1 do
begin
Ext := Uppercase (ExtractFileExt(
ToolServices.GetUnitName(I)));
FName := Uppercase (ExtractFilename (
ToolServices.GetUnitName(I)));
if (Ext <> '.RES') and (Ext <> '.DOF') then
AppendStr (HTML, '<LI> <A HREF=#' + FName + '> ' +
FName + '</A>'#13#10);
end;
// forms list
for I := 0 to ToolServices.GetFormCount - 1 do
begin
FName := Uppercase (ExtractFilename (
ToolServices.GetFormName(I)));
AppendStr (HTML, '<LI> <A HREF=#' + FName + '> ' +
FName + '</A>'#13#10);
end;
AppendStr (HTML, '</UL>'#13#10);
AppendStr (HTML, '<HR>'#13#10);
// add the HTML string to the output buffer
Dest.WriteBuffer (Pointer(HTML)^, Length (HTML));
// generate the HTML code for the units
for I := 0 to ToolServices.GetUnitCount - 1 do
begin
Ext := Uppercase (ExtractFileExt(
ToolServices.GetUnitName(I)));
if (Ext <> '.RES') and (Ext <> '.DOF') then
begin
Source := TFileStream.Create (
ToolServices.GetUnitName(I), fmOpenRead);
Parser := THtmlParser.Create (Source, Dest);
try
Parser.Alone := False;
Parser.Filename := ToolServices.GetUnitName(I);
Parser.Convert;
finally
Parser.Free;
Source.Free;
end;
end; // if
end; // for
// generate the HTML code for forms
for I := 0 to ToolServices.GetFormCount - 1 do
begin
// convert the DFM file to text
BinSource := TFileStream.Create (
ToolServices.GetFormName(I), fmOpenRead);
Source := TMemoryStream.Create;
ObjectResourceToText (BinSource, Source);
Source.Position := 0;
Parser := THtmlParser.Create (Source, Dest);
try
Parser.Alone := False;
Parser.Filename := ToolServices.GetFormName(I);
Parser.SetKeywordType (ktDfm);
Parser.Convert;
finally
Parser.Free;
BinSource.Free;
Source.Free;
end;
end; // for
// add the tail of the HTML file
HTML :=
'<BR><I><CENTER>HTML file generated by PasToWeb, a tool by Marco Cantù<BR>'#13#10 +
Copyright + '</CENTER></I>'#13#10 +
'</BODY> </HTML>';
Dest.WriteBuffer (Pointer(HTML)^, Length (HTML));
finally
Dest.Free;
end;
end;
initialization
PascalKeywords := TStringList.Create;
DfmKeywords := TStringList.Create;
// Pascal Keywords
PascalKeywords.Add ('absolute');
PascalKeywords.Add ('abstract');
PascalKeywords.Add ('and');
PascalKeywords.Add ('array');
PascalKeywords.Add ('as');
PascalKeywords.Add ('asm');
PascalKeywords.Add ('assembler');
PascalKeywords.Add ('at');
PascalKeywords.Add ('automated');
PascalKeywords.Add ('begin');
PascalKeywords.Add ('case');
PascalKeywords.Add ('cdecl');
PascalKeywords.Add ('class');
PascalKeywords.Add ('const');
PascalKeywords.Add ('constructor');
PascalKeywords.Add ('contains');
PascalKeywords.Add ('default');
PascalKeywords.Add ('destructor');
PascalKeywords.Add ('dispid');
PascalKeywords.Add ('dispinterface');
PascalKeywords.Add ('div');
PascalKeywords.Add ('do');
PascalKeywords.Add ('downto');
PascalKeywords.Add ('dynamic');
PascalKeywords.Add ('else');
PascalKeywords.Add ('end');
PascalKeywords.Add ('except');
PascalKeywords.Add ('exports');
PascalKeywords.Add ('external');
PascalKeywords.Add ('file');
PascalKeywords.Add ('finalization');
PascalKeywords.Add ('finally');
PascalKeywords.Add ('for');
PascalKeywords.Add ('forward');
PascalKeywords.Add ('function');
PascalKeywords.Add ('goto');
PascalKeywords.Add ('if');
PascalKeywords.Add ('implementation');
PascalKeywords.Add ('in');
PascalKeywords.Add ('index');
PascalKeywords.Add ('inherited');
PascalKeywords.Add ('initialization');
PascalKeywords.Add ('inline');
PascalKeywords.Add ('interface');
PascalKeywords.Add ('is');
PascalKeywords.Add ('label');
PascalKeywords.Add ('library');
PascalKeywords.Add ('message');
PascalKeywords.Add ('mod');
// PascalKeywords.Add ('name');
PascalKeywords.Add ('nil');
PascalKeywords.Add ('nodefault');
PascalKeywords.Add ('not');
PascalKeywords.Add ('object');
PascalKeywords.Add ('of');
PascalKeywords.Add ('on');
PascalKeywords.Add ('or');
PascalKeywords.Add ('override');
PascalKeywords.Add ('packed');
PascalKeywords.Add ('pascal');
PascalKeywords.Add ('private');
PascalKeywords.Add ('procedure');
PascalKeywords.Add ('program');
PascalKeywords.Add ('property');
PascalKeywords.Add ('protected');
PascalKeywords.Add ('public');
PascalKeywords.Add ('published');
PascalKeywords.Add ('raise');
PascalKeywords.Add ('read');
PascalKeywords.Add ('record');
PascalKeywords.Add ('register');
PascalKeywords.Add ('repeat');
PascalKeywords.Add ('requires');
PascalKeywords.Add ('resident');
PascalKeywords.Add ('set');
PascalKeywords.Add ('shl');
PascalKeywords.Add ('shr');
PascalKeywords.Add ('stdcall');
PascalKeywords.Add ('stored');
PascalKeywords.Add ('string');
PascalKeywords.Add ('then');
PascalKeywords.Add ('threadvar');
PascalKeywords.Add ('to');
PascalKeywords.Add ('try');
PascalKeywords.Add ('type');
PascalKeywords.Add ('unit');
PascalKeywords.Add ('until');
PascalKeywords.Add ('uses');
PascalKeywords.Add ('var');
PascalKeywords.Add ('virtual');
PascalKeywords.Add ('while');
PascalKeywords.Add ('with');
PascalKeywords.Add ('write');
PascalKeywords.Add ('xor');
// DFm keywords
DfmKeywords.Add ('object');
DfmKeywords.Add ('end');
finalization
PascalKeywords.Free;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -