26 lines
553 B
Nix
26 lines
553 B
Nix
let
|
|
elems = import ./elems.nix;
|
|
in rec {
|
|
readMd = md:
|
|
if builtins.isPath md
|
|
then processMd (builtins.readFile md)
|
|
else processMd md;
|
|
processMd = md: (map (c:
|
|
if builtins.isString c
|
|
then mdBlock c
|
|
else "") (builtins.split "\n\n" md));
|
|
|
|
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 elems.h h (builtins.elemAt m 1);
|
|
|
|
heading = block: builtins.match "(#+) (.*)" block;
|
|
}
|