unit beHTML;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Graphics;
type
THTMLHeader = (h1, h2, h3, h4, h5);
THeaderColors = Array[THTMLHeader] of TColor;
THTMLDocument = class
private
FLines: TStrings;
FRawMode: Boolean;
FIndent: Integer;
function Indent: String;
function Raw(const AText: String): String;
function ColorToHTML(AColor: TColor): String;
public
constructor Create;
destructor Destroy; override;
procedure AddEmptyLine;
procedure AddListItem(const AText: String);
procedure AddHeader(AHeader: THTMLHeader; const AText: String);
procedure AddParagraph(const AText: String);
procedure BeginDocument(const ATitle: String; const AHeaderColors: THeaderColors;
ARawMode: Boolean=false);
procedure BeginBulletList;
procedure BeginNumberedList;
function Bold(const AText: String): String;
procedure EndDocument;
procedure EndBulletList;
procedure EndNumberedList;
function Hyperlink(const AText, ALink: String): String;
function Italic(const AText: String): String;
property Lines: TStrings read FLines;
end;
implementation
uses
StrUtils, LCLIntf;
constructor THTMLDocument.Create;
begin
inherited;
FLines := TStringList.Create;
end;
destructor THTMLDocument.Destroy;
begin
FLines.Free;
inherited;
end;
procedure THTMLDocument.AddHeader(AHeader: THTMLHeader; const AText: String);
begin
if FRawMode then
FLines.Add(Raw(AText))
else
FLines.Add(Format('%s
Enter your paragraph text here...
*) procedure THTMLDocument.BeginDocument(const ATitle: String; const AHeaderColors: THeaderColors; ARawMode: Boolean = false); begin FRawMode := ARawMode; FLines.Clear; if not FRawMode then begin FLines.Add(''); FLines.Add(''); FLines.Add(' '); FLines.Add(' '); FLines.Add('' + AText + '
'); end; function THTMLDocument.Bold(const AText: String): String; begin if FRawMode then Result := AText else Result := '' + AText + ''; end; function THTMLDocument.ColorToHTML(AColor: TColor): String; var tmpRGB: LongInt; begin tmpRGB := ColorToRGB(AColor) ; Result := Format('#%.2x%.2x%.2x', [ GetRValue(tmpRGB), GetGValue(tmpRGB), GetBValue(tmpRGB) ]) ; end; procedure THTMLDocument.EndDocument; begin if not FRawMode then begin FLines.Add(' '); FLines.Add(''); end; end; procedure THTMLDocument.EndBulletList; begin if not FRawMode then begin dec(FIndent, 2); FLines.Add(Indent + '