Skip to content

Commit 616a85d

Browse files
committed
Modify active text HTML renderer to support HTML 5
Added support for rendering active text as HTML 5 in addition to XHTML. Implmented in such a way that existing code that expects the original behaviour in rendering XHTML does not need to be modified.
1 parent b7943ec commit 616a85d

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Src/ActiveText.UHTMLRenderer.pas

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ TCSSStyles = class(TObject)
6565
fTagInfoMap: TTagInfoMap;
6666
fIsStartOfTextLine: Boolean;
6767
fLINestingDepth: Cardinal;
68+
fTagGen: THTMLClass;
6869
const
6970
IndentMult = 2;
7071
procedure InitialiseTagInfoMap;
@@ -73,7 +74,7 @@ TCSSStyles = class(TObject)
7374
function MakeOpeningTag(const Elem: IActiveTextActionElem): string;
7475
function MakeClosingTag(const Elem: IActiveTextActionElem): string;
7576
public
76-
constructor Create;
77+
constructor Create(const ATagGenerator: THTMLClass = nil);
7778
destructor Destroy; override;
7879
function Render(ActiveText: IActiveText): string;
7980
end;
@@ -87,13 +88,18 @@ implementation
8788

8889
{ TActiveTextHTML }
8990

90-
constructor TActiveTextHTML.Create;
91+
constructor TActiveTextHTML.Create(const ATagGenerator: THTMLClass);
9192
begin
9293
inherited Create;
9394
fCSSStyles := TCSSStyles.Create;
9495
fBuilder := TStringBuilder.Create;
9596
fLINestingDepth := 0;
9697
InitialiseTagInfoMap;
98+
if not Assigned(ATagGenerator) then
99+
// default behaviour before ATagGenerator parameter was added
100+
fTagGen := TXHTML
101+
else
102+
fTagGen := ATagGenerator;
97103
end;
98104

99105
destructor TActiveTextHTML.Destroy;
@@ -145,7 +151,7 @@ procedure TActiveTextHTML.InitialiseTagInfoMap;
145151
function TActiveTextHTML.MakeClosingTag(const Elem: IActiveTextActionElem):
146152
string;
147153
begin
148-
Result := TXHTML.ClosingTag(fTagInfoMap[Elem.Kind].Name);
154+
Result := fTagGen.ClosingTag(fTagInfoMap[Elem.Kind].Name);
149155
end;
150156

151157
function TActiveTextHTML.MakeOpeningTag(const Elem: IActiveTextActionElem):
@@ -160,7 +166,7 @@ function TActiveTextHTML.MakeOpeningTag(const Elem: IActiveTextActionElem):
160166
Attrs := THTMLAttributes.Create;
161167
Attrs.Add('class', fCSSStyles.ElemClasses[Elem.Kind])
162168
end;
163-
Result := TXHTML.OpeningTag(fTagInfoMap[Elem.Kind].Name, Attrs);
169+
Result := fTagGen.OpeningTag(fTagInfoMap[Elem.Kind].Name, Attrs);
164170
end;
165171

166172
function TActiveTextHTML.Render(ActiveText: IActiveText): string;
@@ -242,7 +248,7 @@ function TActiveTextHTML.RenderText(const TextElem: IActiveTextTextElem):
242248
end
243249
else
244250
Result := '';
245-
Result := Result + TXHTML.Entities(TextElem.Text);
251+
Result := Result + fTagGen.Entities(TextElem.Text);
246252
end;
247253

248254
{ TActiveTextHTML.TCSSStyles }

0 commit comments

Comments
 (0)