Skip to content

Commit c74924c

Browse files
committed
Merge branch 'feature/87-add-html5-save-snippet+unit-option' into develop
Fixes #87
2 parents 1b54e43 + bd3b3ee commit c74924c

24 files changed

+463
-255
lines changed

Docs/Design/FileFormats/saved.html

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ <h2>
7676
<li>
7777
Pascal source files (either .inc or .pas files).
7878
</li>
79+
<li>
80+
HTML 5 files.
81+
</li>
7982
<li>
8083
XHTML files.
8184
</li>
@@ -85,7 +88,7 @@ <h2>
8588
</ul>
8689

8790
<p>
88-
There is no specific file format for these files, except that XHTML and RTF
91+
There is no specific file format for these files, except that HTML 5, XHTML and RTF
8992
files conform to published specifications.
9093
</p>
9194

@@ -135,6 +138,16 @@ <h2>
135138
</li>
136139
</ul>
137140
</dd>
141+
<dt>
142+
HTML 5 files
143+
</dt>
144+
<dd>
145+
<ul class="squashed">
146+
<li>
147+
UTF-8
148+
</li>
149+
</ul>
150+
</dd>
138151
<dt>
139152
XHTML files
140153
</dt>

Src/ActiveText.UHTMLRenderer.pas

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ procedure TActiveTextHTML.InitialiseTagInfoMap;
145145
function TActiveTextHTML.MakeClosingTag(const Elem: IActiveTextActionElem):
146146
string;
147147
begin
148-
Result := THTML.ClosingTag(fTagInfoMap[Elem.Kind].Name);
148+
Result := TXHTML.ClosingTag(fTagInfoMap[Elem.Kind].Name);
149149
end;
150150

151151
function TActiveTextHTML.MakeOpeningTag(const Elem: IActiveTextActionElem):
@@ -160,7 +160,7 @@ function TActiveTextHTML.MakeOpeningTag(const Elem: IActiveTextActionElem):
160160
Attrs := THTMLAttributes.Create;
161161
Attrs.Add('class', fCSSStyles.ElemClasses[Elem.Kind])
162162
end;
163-
Result := THTML.OpeningTag(fTagInfoMap[Elem.Kind].Name, Attrs);
163+
Result := TXHTML.OpeningTag(fTagInfoMap[Elem.Kind].Name, Attrs);
164164
end;
165165

166166
function TActiveTextHTML.Render(ActiveText: IActiveText): string;
@@ -242,7 +242,7 @@ function TActiveTextHTML.RenderText(const TextElem: IActiveTextTextElem):
242242
end
243243
else
244244
Result := '';
245-
Result := Result + THTML.Entities(TextElem.Text);
245+
Result := Result + TXHTML.Entities(TextElem.Text);
246246
end;
247247

248248
{ TActiveTextHTML.TCSSStyles }

Src/Browser.UHighlighter.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function TWBHighlighter.HighlightWord(const Word: string;
194194
begin
195195
// Apply highlight to found text by spanning it with highlight style
196196
SpanAttrs := THTMLAttributes.Create('style', fHighLightStyle);
197-
Range.pasteHTML(THTML.CompoundTag('span', SpanAttrs, Range.htmlText));
197+
Range.pasteHTML(TXHTML.CompoundTag('span', SpanAttrs, Range.htmlText));
198198
Inc(Result);
199199
end
200200
else

Src/FmAboutDlg.pas

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,15 @@ function TAboutDlg.ContribListHTML(ContribList: IStringList):
312312
begin
313313
for Contributor in ContribList do
314314
Result := Result
315-
+ THTML.CompoundTag('div', THTML.Entities(Contributor))
315+
+ TXHTML.CompoundTag('div', TXHTML.Entities(Contributor))
316316
+ EOL;
317317
end
318318
else
319319
begin
320320
// List couldn't be found: display warning message
321321
DivAttrs := THTMLAttributes.Create('class', 'warning');
322-
Result := THTML.CompoundTag(
323-
'div', DivAttrs, THTML.Entities(sNoContributors)
322+
Result := TXHTML.CompoundTag(
323+
'div', DivAttrs, TXHTML.Entities(sNoContributors)
324324
);
325325
end;
326326
end;
@@ -484,15 +484,15 @@ procedure TAboutDlg.InitHTMLFrames;
484484
'DBLicense',
485485
StrIf(
486486
fMetaData.GetLicenseInfo.URL <> '',
487-
THTML.CompoundTag(
487+
TXHTML.CompoundTag(
488488
'a',
489489
THTMLAttributes.Create([
490490
THTMLAttribute.Create('href', fMetaData.GetLicenseInfo.URL),
491491
THTMLAttribute.Create('class', 'external-link')
492492
]),
493-
THTML.Entities(fMetaData.GetLicenseInfo.Name)
493+
TXHTML.Entities(fMetaData.GetLicenseInfo.Name)
494494
),
495-
THTML.Entities(fMetaData.GetLicenseInfo.Name)
495+
TXHTML.Entities(fMetaData.GetLicenseInfo.Name)
496496
)
497497
);
498498
Tplt.ResolvePlaceholderHTML(

Src/FmCompErrorDlg.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ function TCompErrorDlg.TCompilerLog.LogListHTML: string;
341341
begin
342342
Result := '';
343343
for Line in fLog do
344-
Result := Result + THTML.CompoundTag('li', THTML.Entities(Line)) + EOL;
344+
Result := Result + TXHTML.CompoundTag('li', TXHTML.Entities(Line)) + EOL;
345345
end;
346346

347347
end.

Src/FrSourcePrefs.pas

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ implementation
121121

122122
resourcestring
123123
// File type descriptions
124-
sHTMLFileDesc = 'HTML';
124+
sHTML5FileDesc = 'HTML 5';
125+
sXHTMLFileDesc = 'XHTML';
125126
sRTFFileDesc = 'Rich text';
126127
sPascalFileDesc = 'Pascal';
127128
sTextFileDesc = 'Plain text';
@@ -130,7 +131,7 @@ implementation
130131
const
131132
// Maps source code file types to descriptions
132133
cFileDescs: array[TSourceFileType] of string = (
133-
sTextFileDesc, sPascalFileDesc, sHTMLFileDesc, sRTFFileDesc
134+
sTextFileDesc, sPascalFileDesc, sHTML5FileDesc, sXHTMLFileDesc, sRTFFileDesc
134135
);
135136

136137

Src/Help/HTML/dlg_savesnippet.htm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,13 @@ <h1>
7575
file except that the extension is .txt rather than .inc.
7676
</li>
7777
<li>
78-
An HTML file (.html) &ndash; This option writes the source code out as a
78+
A HTML 5 file (.html) &ndash; This option writes the source code out as a
79+
valid HTML 5 document that uses embedded CSS to format the code. The
80+
source code will be syntax highlighted if the <em>Use syntax
81+
highlighting</em> check box is checked.
82+
</li>
83+
<li>
84+
An XHTML file (.html) &ndash; This option writes the source code out as a
7985
valid XHTML document that uses embedded CSS to format the code. The
8086
source code will be syntax highlighted if the <em>Use syntax
8187
highlighting</em> check box is checked.

Src/Help/HTML/dlg_saveunit.htm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ <h1>
6060
file except that the extension is .txt rather than .pas.
6161
</li>
6262
<li>
63-
An HTML file (.html) &ndash; This option writes the source code out as a
63+
A HTML 5 file (.html) &ndash; This option writes the source code out as a
64+
valid HTML 5 document that uses embedded CSS to format the code. The
65+
source code will be syntax highlighted if the <em>Use syntax
66+
highlighting</em> check box is checked.
67+
</li>
68+
<li>
69+
An XHTML file (.html) &ndash; This option writes the source code out as a
6470
valid XHTML document that uses embedded CSS to format the code. The
6571
source code will be syntax highlighted if the <em>Use syntax
6672
highlighting</em> check box is checked.

Src/Help/HTML/menu_file.htm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ <h1>
3737
to a file. The file contains an annotated fragment of Pascal code. The
3838
<a href="dlg_savesnippet.htm">Save Annotated Source</a> dialogue box
3939
is displayed and is used to determine the format of the file being
40-
saved. This can be plain text, a Pascal include file, HTML or RTF. The
41-
latter two options can be syntax highlighted. This option is available
40+
saved. This can be plain text, a Pascal include file, HTML 5, XHTML or RTF. The
41+
latter three options can be syntax highlighted. This option is available
4242
only for <a href="snippet_routine.htm">routine</a> snippets or
4343
categories containing routines. Any snippets in a category that are
4444
not routines are ignored.
@@ -74,7 +74,7 @@ <h1>
7474
snippets and saves it to file. The <a href="dlg_saveunit.htm">Save
7575
Unit</a> dialogue box is displayed and is used to determine the format
7676
of the file being saved. The format can be plain text, a Pascal unit
77-
file, HTML or RTF. The latter two options can be syntax highlighted.
77+
file, HTML 5, XHTML or RTF. The latter three options can be syntax highlighted.
7878
<a href="snippet_freeform.htm">Freeform</a> snippets are not included
7979
in the unit.
8080
</td>

Src/Hiliter.UFileHiliter.pas

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ function TFileHiliter.Hilite(const SourceCode, DocTitle: string): TEncodedData;
9999
begin
100100
case fFileType of
101101
sfRTF: HilitedDocCls := TRTFDocumentHiliter;
102-
sfHTML: HilitedDocCls := TXHTMLDocumentHiliter;
102+
sfXHTML: HilitedDocCls := TXHTMLDocumentHiliter;
103+
sfHTML5: HilitedDocCls := THTML5DocumentHiliter;
103104
else HilitedDocCls := TNulDocumentHiliter;
104105
end;
105106
if fWantHiliting and IsHilitingSupported(fFileType) then
@@ -116,7 +117,7 @@ class function TFileHiliter.IsHilitingSupported(
116117
@return True if file type supports highlighting, false if not.
117118
}
118119
begin
119-
Result := FileType in [sfHTML, sfRTF];
120+
Result := FileType in [sfHTML5, sfXHTML, sfRTF];
120121
end;
121122

122123
end.

Src/Hiliter.UHiliters.pas

Lines changed: 66 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,16 @@ TNulDocumentHiliter = class sealed(TDocumentHiliter)
132132
/// <summary>
133133
/// Creates a highlighted source code document in XHTML format.
134134
/// </summary>
135-
TXHTMLDocumentHiliter = class sealed(TDocumentHiliter)
135+
THTMLDocumentHiliter = class abstract(TDocumentHiliter)
136136
strict private
137137
/// <summary>Generates the CSS rules to be used in the document.</summary>
138138
/// <param name="Attrs">IHiliteAttrs [in] Highlighting styles used in
139139
/// document.</param>
140140
/// <returns>string. CSS rules that apply styles specified in Attrs.
141141
/// </returns>
142142
class function GenerateCSSRules(Attrs: IHiliteAttrs): string;
143+
strict protected
144+
class function BuilderClass: THTMLBuilderClass; virtual; abstract;
143145
public
144146
/// <summary>Creates XHTML document containing highlighted source code.
145147
/// </summary>
@@ -154,6 +156,20 @@ TXHTMLDocumentHiliter = class sealed(TDocumentHiliter)
154156
override;
155157
end;
156158

159+
/// <summary>Creates a highlighted source code document in XHTML format.
160+
/// </summary>
161+
TXHTMLDocumentHiliter = class sealed(THTMLDocumentHiliter)
162+
strict protected
163+
class function BuilderClass: THTMLBuilderClass; override;
164+
end;
165+
166+
/// <summary>Creates a highlighted source code document in HTML5 format.
167+
/// </summary>
168+
THTML5DocumentHiliter = class sealed(THTMLDocumentHiliter)
169+
strict protected
170+
class function BuilderClass: THTMLBuilderClass; override;
171+
end;
172+
157173
type
158174
/// <summary>
159175
/// Creates a highlighted source code document in rich text format.
@@ -242,55 +258,56 @@ TRTFHiliteRenderer = class(THiliteRenderer, IHiliteRenderer)
242258
end;
243259

244260
type
245-
/// <summary>
246-
/// Renders highlighted source code in XHTML format. Generated code is
247-
/// recorded in a given HTML code builder object.
261+
/// <summary>Renders highlighted source code in any supported HTML format.
248262
/// </summary>
249-
/// <remarks>
250-
/// Designed for use with TSyntaxHiliter objects.
251-
/// </remarks>
263+
/// <remarks>Designed for use with <c>TSyntaxHiliter</c> objects.</remarks>
252264
THTMLHiliteRenderer = class(THiliteRenderer, IHiliteRenderer)
253265
strict private
254266
var
255-
/// <summary>Object used to record generated XHTML code.</summary>
267+
/// <summary>Object used to build up the generated HTML.</summary>
256268
fBuilder: THTMLBuilder;
257-
/// <summary>Flag indicating if writing first line of output.</summary>
269+
/// <summary>Flag indicating if writing the first line of output.
270+
/// </summary>
258271
fIsFirstLine: Boolean;
259272
public
260-
/// <summary>Object constructor. Sets up object to render documents.
261-
/// </summary>
262-
/// <param name="Builder">THTMLBuilder [in] Object that receives generated
263-
/// XHTML code.</param>
264-
/// <param name="Attrs">IHiliteAttrs [in] Specifies required highlighting
265-
/// style. If nil document is not highlighted.</param>
273+
/// <summary>Object constructor. Sets up the object to render HTML
274+
/// documents.</summary>
275+
/// <param name="Builder"><c>THTMLBuilder</c> [in] Object used to build the
276+
/// required HTML. <c>Builder</c> must be an instance of a concreate
277+
/// descendant class of <c>THTMLBuilder</c>, which is abstract. The type of
278+
/// <c>Builder</c> determines the type of HTML that is generated.</param>
279+
/// <param name="Attrs"><c>IHiliteAttrs</c> [in] Specifies required
280+
/// highlighting style. If <c>nil</c> the document is not highlighted.
281+
/// </param>
266282
constructor Create(const Builder: THTMLBuilder;
267283
const Attrs: IHiliteAttrs = nil);
268-
/// <summary>Initialises XHTML ready to receive highlighted code.</summary>
269-
/// <remarks>Method of IHiliteRenderer.</remarks>
284+
/// <summary>Initialises the HTML ready to receive highlighted code.
285+
/// </summary>
286+
/// <remarks>Method of <c>IHiliteRenderer</c>.</remarks>
270287
procedure Initialise;
271-
/// <summary>Tidies up XHTML after all highlighted code processed.
288+
/// <summary>Tidies up the HTML after all highlighted code is processed.
272289
/// </summary>
273-
/// <remarks>Method of IHiliteRenderer.</remarks>
290+
/// <remarks>Method of <c>IHiliteRenderer</c>.</remarks>
274291
procedure Finalise;
275-
/// <summary>Emits new line if necessary.</summary>
276-
/// <remarks>Method of IHiliteRenderer.</remarks>
292+
/// <summary>Emits a new line if necessary.</summary>
293+
/// <remarks>Method of <c>IHiliteRenderer</c>.</remarks>
277294
procedure BeginLine;
278295
/// <summary>Does nothing.</summary>
279296
/// <remarks>
280-
/// <para>Handling of new lines is all done by BeginLine.</para>
281-
/// <para>Method of IHiliteRenderer.</para>
297+
/// <para>Handling of new lines is all done by <c>BeginLine</c>.</para>
298+
/// <remarks>Method of <c>IHiliteRenderer</c>.</remarks>
282299
/// </remarks>
283300
procedure EndLine;
284-
/// <summary>Emits any span tag required to style following source code
285-
/// element as specified by Elem.</summary>
286-
/// <remarks>Method of IHiliteRenderer.</remarks>
301+
/// <summary>Emits any &lt;span&gt; tag required to style the following
302+
/// source code element, specified by <c>Elem</c>.</summary>
303+
/// <remarks>Method of <c>IHiliteRenderer</c>.</remarks>
287304
procedure BeforeElem(Elem: THiliteElement);
288-
/// <summary>Writes given source code element text.</summary>
289-
/// <remarks>Method of IHiliteRenderer.</remarks>
305+
/// <summary>Writes the given source code element text.</summary>
306+
/// <remarks>Method of <c>IHiliteRenderer</c>.</remarks>
290307
procedure WriteElemText(const Text: string);
291-
/// <summary>Closes any span tag used to style source code element
292-
/// specified by Elem.</summary>
293-
/// <remarks>Method of IHiliteRenderer.</remarks>
308+
/// <summary>Closes any &lt;span&gt; tag used to style the source code
309+
/// element specified by <c>Elem</c>.</summary>
310+
/// <remarks>Method of <c>IHiliteRenderer</c>.</remarks>
294311
procedure AfterElem(Elem: THiliteElement);
295312
end;
296313

@@ -372,9 +389,9 @@ class function TNulDocumentHiliter.Hilite(const RawCode: string;
372389
Result := TEncodedData.Create(RawCode, etUnicode);
373390
end;
374391

375-
{ TXHTMLDocumentHiliter }
392+
{ THTMLDocumentHiliter }
376393

377-
class function TXHTMLDocumentHiliter.GenerateCSSRules(Attrs: IHiliteAttrs):
394+
class function THTMLDocumentHiliter.GenerateCSSRules(Attrs: IHiliteAttrs):
378395
string;
379396
var
380397
CSSBuilder: TCSSBuilder; // builds CSS code
@@ -396,7 +413,7 @@ class function TXHTMLDocumentHiliter.GenerateCSSRules(Attrs: IHiliteAttrs):
396413
end;
397414
end;
398415

399-
class function TXHTMLDocumentHiliter.Hilite(const RawCode: string;
416+
class function THTMLDocumentHiliter.Hilite(const RawCode: string;
400417
Attrs: IHiliteAttrs; const Title: string): TEncodedData;
401418
resourcestring
402419
// Default document title
@@ -405,7 +422,7 @@ class function TXHTMLDocumentHiliter.Hilite(const RawCode: string;
405422
Renderer: IHiliteRenderer; // XHTML renderer object
406423
Builder: THTMLBuilder; // object used to construct XHTML document
407424
begin
408-
Builder := THTMLBuilder.Create;
425+
Builder := BuilderClass.Create;
409426
try
410427
if Title <> '' then
411428
Builder.Title := Title
@@ -420,6 +437,20 @@ class function TXHTMLDocumentHiliter.Hilite(const RawCode: string;
420437
end;
421438
end;
422439

440+
{ TXHTMLDocumentHiliter }
441+
442+
class function TXHTMLDocumentHiliter.BuilderClass: THTMLBuilderClass;
443+
begin
444+
Result := TXHTMLBuilder;
445+
end;
446+
447+
{ THTML5DocumentHiliter }
448+
449+
class function THTML5DocumentHiliter.BuilderClass: THTMLBuilderClass;
450+
begin
451+
Result := THTML5Builder;
452+
end;
453+
423454
{ TRTFDocumentHiliter }
424455

425456
class function TRTFDocumentHiliter.Hilite(const RawCode: string;

0 commit comments

Comments
 (0)