insert elems into md

This commit is contained in:
tristan 2024-02-11 08:25:09 +00:00
parent 62f3749709
commit 6509c8c827

View file

@ -1,19 +1,16 @@
let
elems = import ./elems.nix;
html = import ./html.nix;
in rec {
processMd = md:
rec {
processMd = elems: md:
if builtins.isPath md
then processStr (builtins.readFile md)
else processStr md;
then processStr elems (builtins.readFile md)
else processStr elems md;
recReadMd = toPage: root:
recReadMd = toPage: elems: root:
assert builtins.isPath root;
builtins.mapAttrs (path: type:
if type == "directory"
then recReadMd (root + (/. + path))
else if type == "regular"
then toPage (processMd (root + (/. + path)))
then toPage (processMd elems (root + (/. + path)))
else throw "Cannot read ${path}, file type ${type}") (builtins.readDir root);
recFixAppendix = site:
@ -28,13 +25,13 @@ in rec {
fixAppendix = builtins.replaceStrings [".md"] [".html"];
readDir = toPage: root: recFixAppendix (recReadMd toPage root);
readDir = toPage: elems: root: recFixAppendix (recReadMd toPage elems root);
splitList = block:
map listItem (builtins.filter (s: builtins.isString s && s != "")
splitList = elems: block:
map listItem elems (builtins.filter (s: builtins.isString s && s != "")
(builtins.split "\n" block));
listItem = str: let
listItem = elems: str: let
li = builtins.match "- (.*)" str;
checkbox = builtins.match "- \\[(.)] (.*)" str;
checked = builtins.elemAt checkbox 0;
@ -93,7 +90,7 @@ in rec {
basicRule = matcher: elem: rule matcher (m: elem (builtins.elemAt m 1));
processStr = applyRules 0 [
processStr = elems: applyRules 0 [
(basicRule (wrap "\\^") elems.sup)
(basicRule (wrap "~") elems.sub)
(basicRule (wrap "\\*") elems.em)
@ -106,8 +103,8 @@ in rec {
(rule (contains "\\[(.*)]\\((.*)\\)") (m: let
href = builtins.elemAt m 2;
text = builtins.elemAt m 1;
in (elems.a href text)))
list
in (elems.a {inherit href;} text)))
(list elems)
(basicRule "(.*\n\n)?(.+)\n(.*)?" elems.p)
(basicRule "(.*\n\n)?```(.*)```(.*)?" (elems.textarea {readonly = true;}))
(basicRule (containsBreak "###### ([^\n]+)") (elems.h6))
@ -116,10 +113,10 @@ in rec {
(basicRule (containsBreak "### ([^\n]+)") (elems.h3))
(basicRule (containsBreak "## ([^\n]+)") (elems.h2))
(basicRule (containsBreak "# ([^\n]+)") (elems.h1))
(basicRule (containsBreak "<(${linkmatcher})>") (m: elems.a m m))
(basicRule (containsBreak "<(${linkmatcher})>") (m: elems.a {href = m;} m))
];
list = let
list = elems: let
addCheckboxes = basicRule "()\\[(.)] (.*)" (check:
elems.input {
type = "checkbox";