TSynExporterHTML does not generate doctype and content-type information
Original Reporter info from Mantis: Bart @flyingsheep
-
Reporter name: Bart Broersma
Original Reporter info from Mantis: Bart @flyingsheep
- Reporter name: Bart Broersma
Description:
Here's a typical fragment of the exporters export:
&LtPos;html>
&LtPos;head>&LtPos;/head>
&LtPos;body>&LtPos;b>unit &LtPos;/b>main;
&LtPos;i>{$assertions on}
{mode objfpc}{
H+}
//{$mode delphi}
&LtPos;/i>&LtPos;b>interface&LtPos;/b>
The file itself seems to be written with string-encoding "current codepage", but the file itself does not mention this.
Here's a fragment of a "proper" html file:
&LtPos;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
&LtPos;html>
&LtPos;head>
&LtPos;meta http-equiv="content-type" content="text/html; charset=utf-8">
I know that in general it is the server's task to inform the client of the charset that served html paes have, but that only works if the charset used, is indeed the charset that the server says is serves *
Since we don't know that is the case, we'ld better insert some content-type info which states what the charset is.
Preferrably the charset of the export should be configurable, if that cannot be done, the better choice IMO would be to default to UTF-8.
B.t.w. the exporter also seems to assume that the input (TStrings) is encoded as windows-1252, which is not the default encoding at least for TSynEdit.
* My server says that it serves html as UTF-8. If I place an html file create with the exporter on my server, your browser wrongly assumes it is utf-8, and it may very well display wrong.
Steps to reproduce:
Put a TSynEdit and a TSynExporterHTML on a form, with a highlighter attached.
I used this code to export:
procedure TForm1.Button1Click(Sender: TObject);
begin
HtmlExp.CreateHTMLFragment := False;
HtmlExp.ExportAll(SynEdit1.Lines);
HtmlExp.SaveToFile('test.html');
end;
(Q: how to get rid of the annoying HTML fragment (which is meant for copying to clipboard)?)
Mantis conversion info:
- Mantis ID: 28627
- OS: Window
- OS Build: Win7
- Build: r49759
- Platform: i386
- Version: 1.5 (SVN)
- Fixed in version: 1.6
- Fixed in revision: r49820 (#9c3d4cb5)
- Monitored by: » @martin_frb (Martin Friebe)
- Target version: 1.6