forked from DelphiCodeCoverage/DelphiCodeCoverage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHtmlHelper.pas
More file actions
130 lines (105 loc) · 3.7 KB
/
Copy pathHtmlHelper.pas
File metadata and controls
130 lines (105 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
(***********************************************************************)
(* Delphi Code Coverage *)
(* *)
(* A quick hack of a Code Coverage Tool for Delphi *)
(* by Christer Fahlgren and Nick Ring *)
(* *)
(* This Source Code Form is subject to the terms of the Mozilla Public *)
(* License, v. 2.0. If a copy of the MPL was not distributed with this *)
(* file, You can obtain one at http://mozilla.org/MPL/2.0/. *)
unit HtmlHelper;
interface
function StartTag(const ATag: string; const ATagAttributes: string = ''): string;
function EndTag(const ATag: string): string;
function WrapTag(const AValue: string; const ATag: string; const ATagAttributes: string = ''): string;
function p(const AValue: string): string;
function bold(const AValue: string): string;
function heading(const AValue: string; const ALevel: Byte): string;
function td(const AValue: string): string;
function th(const AValue: string): string;
function tr(const AValue: string; const AAttributes: string = ''): string;
function table(const AValue: string; const AAttributes: string = ''): string;
function em(const AValue: string): string;
function pre(const AValue: string): string;
function link(
const AValue: string;
const AHref: string;
const ATitle: string = ''): string;
function lineBreak: string;
function italics(const AValue: string): string;
implementation
uses
System.SysUtils;
function StartTag(const ATag: string; const ATagAttributes: string = ''): string;
begin
Result := '<' + LowerCase(ATag);
if ATagAttributes <> '' then
Result := Result + ' ' + ATagAttributes;
Result := Trim(Result) + '>';
end;
function EndTag(const ATag: string): string;
begin
Result := '</' + LowerCase(ATag) + '>';
end;
function WrapTag(const AValue: string; const ATag: string; const ATagAttributes: string = ''): string;
begin
Result := StartTag(ATag, ATagAttributes) + AValue + EndTag(ATag);
end;
function p(const AValue: string): string;
begin
Result := WrapTag(AValue, 'p');
end;
function bold(const AValue: string): string;
begin
Result := WrapTag(AValue, 'strong');
end;
function heading(const AValue: string; const ALevel: Byte): string;
begin
Result := WrapTag(AValue, 'h' + IntToStr(ALevel));
end;
function td(const AValue: string): string;
begin
Result := WrapTag(AValue, 'td');
end;
function th(const AValue: string): string;
begin
Result := WrapTag(AValue, 'th');
end;
function tr(const AValue: string; const AAttributes: string = ''): string;
begin
Result := WrapTag(AValue, 'tr', AAttributes);
end;
function table(const AValue: string; const AAttributes: string = ''): string;
begin
Result := WrapTag(AValue, 'table', AAttributes);
end;
function em(const AValue: string): string;
begin
Result := WrapTag(AValue, 'em');
end;
function pre(const AValue: string): string;
begin
Result := WrapTag(AValue, 'pre', 'style="display:inline;"');
end;
function link(
const AValue: string;
const AHref: string;
const ATitle: string = ''): string;
var
TagAttributes: string;
begin
if Trim(AHref) <> '' then
TagAttributes := 'href="' + Trim(AHref) + '"';
if Trim(ATitle) <> '' then
TagAttributes := TagAttributes + ' title="' + Trim(ATitle) + '"';
Result := WrapTag(AValue, 'a', TagAttributes);
end;
function lineBreak: string;
begin
Result := '<br />';
end;
function italics(const AValue: string): string;
begin
Result := WrapTag(AValue, 'i');
end;
end.