Markdown-to-HTML processor for mORMot v2.*.
- Four dialects: Daring Fireball, TxtMark, CommonMark, GitHub (GFM)
- Single unit (
mormot.ext.markdown.pas) - no extra dependencies beyond mORMot v2 core - Safe mode - filters
<script>,<applet>, and other unsafe HTML elements - Tables (with
<thead>/<tbody>, column alignment), fenced code blocks, smart typography, strikethrough, heading IDs, task lists, bare URL autolinks
uses
mormot.ext.markdown;
var
html: RawUtf8;
begin
html := MarkdownToHtml('# Hello World');
end;var
md: TMarkdownProcessor;
begin
md := TMarkdownProcessor.Create(mdGitHub);
try
md.SafeMode := True;
html := md.Process('Some **markdown** text');
finally
md.Free;
end;
end;| Dialect | Description |
|---|---|
mdDaringFireball |
The original - bare minimum |
mdTxtMark |
+ smart typography, fenced code, heading IDs |
mdCommonMark |
+ tables, strikethrough, sub/sup, ins, mark, math |
mdGitHub |
GFM - like CommonMark + task lists, bare URL autolinks, without sub/sup/ins/mark/math |
md := TMarkdownProcessor.Create(mdGitHub); // GFM, most common
md := TMarkdownProcessor.Create(mdCommonMark); // defaultmdGitHub follows the GFM spec: tables, strikethrough (~~text~~), task lists (- [x] done), and bare URL autolinks (https://..., www....). CommonMark-only extensions (++ins++, ==mark==, ~sub~, $math$) are not active in GFM.
Subclass TMarkdownDecorator to customize the generated HTML tags:
type
TMyDecorator = class(TMarkdownDecorator)
public
procedure OpenParagraph(W: TTextWriter); override;
end;
procedure TMyDecorator.OpenParagraph(W: TTextWriter);
begin
W.AddShort('<p class="custom">');
end;
md := TMarkdownProcessor.Create(mdGitHub, TMyDecorator.Create);See demos/vcl-markdown/ for a VCL app with live preview.
Tests cover all dialects, GFM extensions, and edge cases: