add checkboxes

This commit is contained in:
tristan 2024-01-01 20:27:05 +00:00
parent c29ff7b22e
commit 4f28cbfda7
5 changed files with 60 additions and 35 deletions

View file

@ -38,6 +38,7 @@ nix build .#raw
- [X] global styles
- [X] custom components with styles
- [X] component extend / inheritance
- [ ] templating
### markdown
@ -46,12 +47,15 @@ nix build .#raw
- [X] paragraphs
- [ ] tables
- [X] lists
- [ ] checkboxes
- [ ] embedded lists
- [X] checkboxes
- [ ] images
- [ ] links
- [X] codeblocks
- [ ] subscript
- [X] highlight
- [X] italics
- [X] bold
- [X] `codeblocks`
- [X] ~superscript~
- [X] ^subscript^
- [X] ==highlight==
- [X] *italics*
- [X] **bold**
- [X] ~~strikethrough~~

View file

@ -3,8 +3,9 @@ let
assert builtins.isString key;
if builtins.isAttrs value then
builtins.trace "Skipping ${key} as it is a set" ""
else if value == "" || value == [ ] then
else if value == "" || value == [ ] || value == false then
""
else if value == true then key
else
''${key}="${toString value}"'';
in rec {

View file

@ -69,13 +69,25 @@ in rec {
matchThen "(```)(.*)(```)" block (m: elems.code (builtins.elemAt m 1));
list = block:
matchThen (let item = "- .+";
in ''
(${item}
)*(${item}
matchThen (
''
(- .+
)*(- .+
?)'') block (m:
elems.List (builtins.filter (s: builtins.isString s && s != "")
(builtins.split "[:blank:]*- " block)));
elems.List ( splitList block ));
splitList = block: map (listItem) (builtins.filter
(s: builtins.isString s && s != "")
(builtins.split "\n" block));
listItem = str:
let
li = builtins.match "- (.*)" str;
checkbox = builtins.match "- \\[(.)] (.*)" str;
checked = builtins.elemAt checkbox 0;
content = builtins.elemAt checkbox 1;
in if checkbox == null then li else
[(elems.input {type = "checkbox"; checked = checked != " "; disabled = true;}) content];
replace = matcher: apply: block:
(let

View file

@ -132,4 +132,9 @@ in with html; [
removeDunders = true;
}))
(it "renders on / off attrs" ({
actual = toString (tag "p" {on = true; off = false;});
expected = "<p on></p>";
}))
]

View file

@ -34,13 +34,12 @@ in with md; [
'';
expected = {
matched = true;
block = elems.List [''
something
''];
block = elems.List ["something"];
};
asJSON = true;
}))
(it "matches a list of many elements" ({
(it "makes a list of many elements" ({
actual = list ''
- something
- something else
@ -48,14 +47,28 @@ in with md; [
expected = {
matched = true;
block = elems.List [
''
something
''
''
something else
''
"something"
"something else"
];
};
asJSON = true;
}))
(it "makes a list of many checkboxes" ({
actual = list ''
- [ ] something
- [X] something else
'';
expected = {
matched = true;
block = elems.List [
[(elems.input {type = "checkbox"; disabled = true; checked = false; } "")
"something"]
[(elems.input {type = "checkbox"; disabled = true; checked = true; } "")
"something else"]
];
};
asJSON = true;
}))
(it "matches a list with no whitespace around" ({
@ -65,12 +78,11 @@ in with md; [
expected = {
matched = true;
block = elems.List [
''
something
''
"something"
"something else"
];
};
asJSON = true;
}))
(it "doesnt match not a list" (let str = "blah blah";
@ -82,15 +94,6 @@ in with md; [
};
}))
(it "makes a list" ({
actual = mdBlock ''
- something
'';
expected = elems.List [''
something
''];
}))
(it "finds surrounded parts" ({
actual = replace (wrap "\\*\\*") elems.strong ''
this text **may** contain **bold** words inside it.