add md code block support (basic)

This commit is contained in:
tristan 2024-01-01 14:06:54 +00:00
parent 3ceb580768
commit fafff120f9
3 changed files with 30 additions and 11 deletions

View file

@ -46,9 +46,22 @@ in rec {
mdBlock = block:
let
m = heading block;
h = if m == null then 0 else builtins.stringLength (builtins.elemAt m 0);
in if m == null then elems.p { } block else H h (builtins.elemAt m 1);
h = heading block;
c = code block;
in (if h.matched then h.block else
if c.matched then c.block else
elems.p block);
heading = block: builtins.match "(#+) (.*)" block;
heading = block: let
m = builtins.match "(#+) (.*)" block;
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); };
code = block: let
m = builtins.match "(```)(.*)(```)" block;
in
if m == null then { matched = false; inherit block; }
else { matched = true; block = elems.code (builtins.elemAt m 1); };
}