-
Notifications
You must be signed in to change notification settings - Fork 1
/
marked.pas
44 lines (31 loc) · 918 Bytes
/
marked.pas
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
unit marked;
{$mode objfpc}{$H+}
interface
uses
Types, Classes, Web;
type
{ TMarkdownFile }
TMarkdownFile = class(TComponent)
private
FTarget: TJSHTMLElement;
FFile: TStringStream;
procedure onLoaded(Sender: TObject);
public
constructor Create(AOwner: TComponent; const FileName, target: string; onLoadError: TStringNotifyEventRef);
end;
function markdown(const s: string): string; external name 'window.marked';
implementation
{ TMarkdownFile }
procedure TMarkdownFile.onLoaded(Sender: TObject);
begin
FTarget.innerHTML:=markdown(FFile.DataString);
end;
constructor TMarkdownFile.Create(AOwner: TComponent; const FileName,
target: string; onLoadError: TStringNotifyEventRef);
begin
inherited Create(AOwner);
FTarget:=TJSHTMLElement(document.getElementById(target));
FFile:=TStringStream.Create;
FFile.LoadFromURL(FileName, True, @onLoaded, onLoadError);
end;
end.