@@ -18,6 +18,7 @@ interface
1818 // Project
1919 UBaseObjects,
2020 UEncodings,
21+ UHTMLSnippetDoc,
2122 USaveSourceDlg,
2223 USourceFileInfo,
2324 UView;
@@ -39,6 +40,17 @@ TSaveInfoMgr = class(TNoPublicConstructObject)
3940 class function GenerateRichText (View : IView; const AUseHiliting: Boolean):
4041 TEncodedData; static;
4142
43+ // / <summary>Returns encoded data containing a HTML representation of the
44+ // / required snippet information.</summary>
45+ // / <param name="AUseHiliting"><c>Boolean</c> [in] Determines whether
46+ // / source code is syntax highlighted or not.</param>
47+ // / <param name="GeneratorClass"><c>THTMLSnippetDocClass</c> [in] Class of
48+ // / object used to generate the required flavour of HTML.</param>
49+ // / <returns><c>TEncodedData</c>. Required HTML document, encoded as UTF-8.
50+ // / </returns>
51+ function GenerateHTML (const AUseHiliting: Boolean;
52+ const GeneratorClass: THTMLSnippetDocClass): TEncodedData;
53+
4254 // / <summary>Returns encoded data containing a plain text representation of
4355 // / information about the snippet represented by the given view.</summary>
4456 function GeneratePlainText : TEncodedData;
@@ -191,6 +203,24 @@ class procedure TSaveInfoMgr.Execute(View: IView);
191203 end ;
192204end ;
193205
206+ function TSaveInfoMgr.GenerateHTML (const AUseHiliting: Boolean;
207+ const GeneratorClass: THTMLSnippetDocClass): TEncodedData;
208+ var
209+ Doc: THTMLSnippetDoc; // object that generates RTF document
210+ HiliteAttrs: IHiliteAttrs; // syntax highlighter formatting attributes
211+ begin
212+ if (fView as ISnippetView).Snippet.HiliteSource and AUseHiliting then
213+ HiliteAttrs := THiliteAttrsFactory.CreateUserAttrs
214+ else
215+ HiliteAttrs := THiliteAttrsFactory.CreateNulAttrs;
216+ Doc := GeneratorClass.Create(HiliteAttrs);
217+ try
218+ Result := Doc.Generate((fView as ISnippetView).Snippet);
219+ finally
220+ Doc.Free;
221+ end ;
222+ end ;
223+
194224function TSaveInfoMgr.GenerateOutput (const FileType: TSourceFileType):
195225 TEncodedData;
196226var
@@ -201,6 +231,8 @@ function TSaveInfoMgr.GenerateOutput(const FileType: TSourceFileType):
201231 case FileType of
202232 sfRTF: Result := GenerateRichText(fView, UseHiliting);
203233 sfText: Result := GeneratePlainText;
234+ sfHTML5: Result := GenerateHTML(UseHiliting, THTML5SnippetDoc);
235+ sfXHTML: Result := GenerateHTML(UseHiliting, TXHTMLSnippetDoc);
204236 end ;
205237end ;
206238
@@ -264,6 +296,8 @@ constructor TSaveInfoMgr.InternalCreate(AView: IView);
264296 // descriptions of supported file filter strings
265297 sRTFDesc = ' Rich text file' ;
266298 sTextDesc = ' Plain text file' ;
299+ sHTML5Desc = ' HTML 5 file' ;
300+ sXHTMLDesc = ' XHTML file' ;
267301begin
268302 inherited InternalCreate;
269303 fView := AView;
@@ -286,6 +320,21 @@ constructor TSaveInfoMgr.InternalCreate(AView: IView);
286320 TSourceFileEncoding.Create(etSysDefault, sANSIDefaultEncoding)
287321 ]
288322 );
323+ fSourceFileInfo.FileTypeInfo[sfHTML5] := TSourceFileTypeInfo.Create(
324+ ' .html' ,
325+ sHTML5Desc,
326+ [
327+ TSourceFileEncoding.Create(etUTF8, sUTF8Encoding)
328+ ]
329+ );
330+ fSourceFileInfo.DefaultFileName := sDefFileName;
331+ fSourceFileInfo.FileTypeInfo[sfXHTML] := TSourceFileTypeInfo.Create(
332+ ' .html' ,
333+ sXHTMLDesc,
334+ [
335+ TSourceFileEncoding.Create(etUTF8, sUTF8Encoding)
336+ ]
337+ );
289338 fSourceFileInfo.DefaultFileName := sDefFileName;
290339
291340 fSaveDlg := TSaveSourceDlg.Create(nil );
@@ -314,21 +363,28 @@ procedure TSaveInfoMgr.PreviewHandler(Sender: TObject);
314363 case SelectedFileType of
315364 sfRTF:
316365 begin
366+ // RTF is previewed as is
317367 PreviewDocType := dtRTF;
318368 PreviewFileType := sfRTF;
319369 end ;
320370 sfText:
321371 begin
372+ // Plain text us previewed as is
322373 PreviewDocType := dtPlainText;
323374 PreviewFileType := sfText;
324375 end ;
376+ sfHTML5, sfXHTML:
377+ begin
378+ // Both HTML 5 and XHTML are previewed as XHTML
379+ PreviewDocType := dtHTML;
380+ PreviewFileType := sfXHTML;
381+ end ;
325382 else
326383 raise Exception.Create(
327384 ClassName + ' .PreviewHandler: unsupported file type'
328385 );
329386 end ;
330- // Display preview dialog box. We use save dialog as owner to ensure preview
331- // dialog box is aligned over save dialog box
387+ // Display preview dialogue box aligned over the save dialogue
332388 TPreviewDlg.Execute(
333389 fSaveDlg,
334390 GenerateOutput(PreviewFileType),
0 commit comments