remove old doc func and fix md lists

This commit is contained in:
tristan 2024-01-03 14:56:48 +00:00
parent 93799cac12
commit 63f1c014af
6 changed files with 74 additions and 71 deletions

View file

@ -1,5 +1,6 @@
let
elems = import ./elems.nix;
html = import ./html.nix;
in rec {
processMd = md:
if builtins.isPath md
@ -30,7 +31,10 @@ in rec {
readDir = root: recFixAppendix (recReadMd root);
mdToPage = md:
elems.Doc {} [[(elems.title {} "markdown file")] (processMd md)];
html.document {
head = [];
body = elems.main (elems.article (processMd md));
};
splitList = block:
map listItem (builtins.filter (s: builtins.isString s && s != "")
@ -53,26 +57,29 @@ in rec {
content
];
replace = regex: apply: block: (let
m = builtins.match regex block;
before = let
v = builtins.elemAt m 0;
replace = regex: apply: block:
assert builtins.isString block; (let
m = builtins.match regex block;
before = builtins.elemAt m 0;
after = toString (builtins.elemAt m (matchCount - 1));
matchCount = builtins.length m;
in
if v == null
then ""
else v;
after = toString (builtins.elemAt m (matchCount - 1));
matchCount = builtins.length m;
in
if m == null
then block
else (replace regex apply before) + (apply m) + after);
if m == null
then block
else
(
if before == null
then ""
else replace regex apply before
)
+ (apply m)
+ after);
rule = matcher: apply: blocks:
map (b:
if builtins.isString b
then replace matcher apply b
else b)
map (block:
if builtins.isString block
then replace matcher apply block
else block)
blocks;
applyRules = i: rules: input: let
@ -117,14 +124,14 @@ in rec {
(basicRule (containsBreak "<(${linkmatcher})>") (m: elems.a m m))
];
list = rule "(.*\n)([^-][^\n]+\n)((- [^\n]+\n)+)(.*)" (
list = rule "((.*)(\n([^-\n][^\n]+)?\n))?((- [^\n]+\n)+)(.*)" (
l: (elems.ul (basicRule "(.*\n)?- ([^\n]+)\n(.*)" (m:
elems.li (basicRule "()\\[(.)](.*)" (check:
elems.li (basicRule "()\\[(.)] (.*)" (check:
elems.input {
type = "checkbox";
checked = check != " ";
disabled = true;
}) [m])) [(builtins.elemAt l 2)]))
}) [m])) [(builtins.elemAt l 4)]))
);
linkmatcher = "[-[:alnum:].%?&#=:/]+";