IntegerStyle setze ich absichtlich auf 0 damit nicht zusätzliche für mich überflüssige Tags entstehen.
Falls es einen besseren Weg gibt lasst es mich wissen

Code: Alles auswählen
unit pas2html;
{$ifdef fpc}
{$mode objfpc}{$H+}
{$endif}
interface
uses
Windows, Classes, SysUtils, SynHighlighterPas, SynExportHTML, Interfaces;
function ConvertPasToHtm(const InputFileName: string): string;
implementation
function ConvertPasToHtm(const InputFileName: string): string;
var
CodeLines: TStringList;
Syn: TSynPasSyn;
Exp: TSynExporterHTML;
stream: TMemoryStream;
s: Ansistring;
begin
result := '';
stream := TMemoryStream.Create;
try
stream.LoadFromFile(InputFileName);
CodeLines := TStringList.Create;
try
SetString(s, stream.Memory, stream.Size);
CodeLines.Text := s;
stream.Clear;
Syn := TSynPasSyn.Create(nil);
try
//syntax highlighter settings
Syn.AsmAttri.Foreground := RGB($FF,$00,$FF);
Syn.CommentAttri.Foreground := RGB($00,$80,$00);
Syn.CommentAttri.IntegerStyle := $0;
Syn.CaseLabelAttri.Foreground := RGB($FF,$00,$00);
Syn.DirectiveAttri.Foreground := RGB($00,$64,$00);
Syn.DirectiveAttri.IntegerStyle := 0;
Syn.IDEDirectiveAttri.Foreground := RGB($55,$6B,$2F);
Syn.IDEDirectiveAttri.IntegerStyle := 0;
Syn.IdentifierAttri.Foreground := RGB($19,$19,$70);
Syn.KeyAttri.Foreground := RGB($00,$00,$FF);
Syn.KeyAttri.IntegerStyle := 0;
Syn.NumberAttri.Foreground := RGB($D2,$69,$1E);
Syn.SpaceAttri.Foreground := RGB($CA,$CA,$CA);
Syn.StringAttri.Foreground := RGB($A2,$25,$25);
Syn.SymbolAttri.Foreground := RGB($2F,$4F,$4F);
// export ALines to HTML, as HTML fragment in text format
Exp := TSynExporterHTML.Create(nil);
try
Exp.Highlighter := Syn;
Exp.ExportAsText := TRUE;
Exp.CreateHTMLFragment := TRUE;
Exp.ExportAll(CodeLines);
Exp.SaveToStream(stream);
SetString(result, stream.Memory, stream.Size);
finally
Exp.Free;
end;
finally
Syn.Free;
end;
finally
CodeLines.Free;
end;
finally
stream.Free;
end;
end;
end.