add md lists support

This commit is contained in:
tristan 2024-01-01 14:51:59 +00:00
parent fafff120f9
commit 496d3667de
3 changed files with 64 additions and 12 deletions

View file

@ -45,23 +45,33 @@ in rec {
elems.Doc { } [ [ (elems.title { } "markdown file") ] (readMd md) ];
mdBlock = block:
let
(let
h = heading block;
c = code block;
ul = list block;
in (if h.matched then h.block else
if c.matched then c.block else
elems.p block);
if ul.matched then ul.block else
elems.p block));
heading = block: let
m = builtins.match "(#+) (.*)" block;
heading = block: matchThen "(#+) (.*)" block (m:
let
l = builtins.stringLength (builtins.elemAt m 0);
in
if m == null then { matched = false; inherit block; }
else { matched = true; block = H l (builtins.elemAt m 1); };
in H l (builtins.elemAt m 1));
code = block: let
m = builtins.match "(```)(.*)(```)" block;
code = block: matchThen "(```)(.*)(```)" block (m:
elems.code (builtins.elemAt m 1));
list = block: matchThen (let item = "- .+"; in "(${item}\n)*(${item}\n?)") block (m:
elems.List (builtins.filter ( s: builtins.isString s && s!="" ) (builtins.split "[:blank:]*- " block)));
matchThen = matcher: block: func:
let
m = builtins.match matcher block;
in
if m == null then { matched = false; inherit block; }
else { matched = true; block = elems.code (builtins.elemAt m 1); };
if m == null then dontMatch block
else { matched = true; block = func m; };
dontMatch = block: { matched = false; inherit block; };
}