add checkboxes
This commit is contained in:
parent
c29ff7b22e
commit
4f28cbfda7
16
README.md
16
README.md
|
@ -38,6 +38,7 @@ nix build .#raw
|
||||||
- [X] global styles
|
- [X] global styles
|
||||||
- [X] custom components with styles
|
- [X] custom components with styles
|
||||||
- [X] component extend / inheritance
|
- [X] component extend / inheritance
|
||||||
|
- [ ] templating
|
||||||
|
|
||||||
### markdown
|
### markdown
|
||||||
|
|
||||||
|
@ -46,12 +47,15 @@ nix build .#raw
|
||||||
- [X] paragraphs
|
- [X] paragraphs
|
||||||
- [ ] tables
|
- [ ] tables
|
||||||
- [X] lists
|
- [X] lists
|
||||||
- [ ] checkboxes
|
- [ ] embedded lists
|
||||||
|
- [X] checkboxes
|
||||||
- [ ] images
|
- [ ] images
|
||||||
- [ ] links
|
- [ ] links
|
||||||
- [X] codeblocks
|
- [X] `codeblocks`
|
||||||
- [ ] subscript
|
- [X] ~superscript~
|
||||||
- [X] highlight
|
- [X] ^subscript^
|
||||||
- [X] italics
|
- [X] ==highlight==
|
||||||
- [X] bold
|
- [X] *italics*
|
||||||
|
- [X] **bold**
|
||||||
|
- [X] ~~strikethrough~~
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,9 @@ let
|
||||||
assert builtins.isString key;
|
assert builtins.isString key;
|
||||||
if builtins.isAttrs value then
|
if builtins.isAttrs value then
|
||||||
builtins.trace "Skipping ${key} as it is a set" ""
|
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
|
else
|
||||||
''${key}="${toString value}"'';
|
''${key}="${toString value}"'';
|
||||||
in rec {
|
in rec {
|
||||||
|
|
|
@ -69,13 +69,25 @@ in rec {
|
||||||
matchThen "(```)(.*)(```)" block (m: elems.code (builtins.elemAt m 1));
|
matchThen "(```)(.*)(```)" block (m: elems.code (builtins.elemAt m 1));
|
||||||
|
|
||||||
list = block:
|
list = block:
|
||||||
matchThen (let item = "- .+";
|
matchThen (
|
||||||
in ''
|
''
|
||||||
(${item}
|
(- .+
|
||||||
)*(${item}
|
)*(- .+
|
||||||
?)'') block (m:
|
?)'') block (m:
|
||||||
elems.List (builtins.filter (s: builtins.isString s && s != "")
|
elems.List ( splitList block ));
|
||||||
(builtins.split "[:blank:]*- " 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:
|
replace = matcher: apply: block:
|
||||||
(let
|
(let
|
||||||
|
|
|
@ -132,4 +132,9 @@ in with html; [
|
||||||
removeDunders = true;
|
removeDunders = true;
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
(it "renders on / off attrs" ({
|
||||||
|
actual = toString (tag "p" {on = true; off = false;});
|
||||||
|
expected = "<p on></p>";
|
||||||
|
}))
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -34,13 +34,12 @@ in with md; [
|
||||||
'';
|
'';
|
||||||
expected = {
|
expected = {
|
||||||
matched = true;
|
matched = true;
|
||||||
block = elems.List [''
|
block = elems.List ["something"];
|
||||||
something
|
|
||||||
''];
|
|
||||||
};
|
};
|
||||||
|
asJSON = true;
|
||||||
}))
|
}))
|
||||||
|
|
||||||
(it "matches a list of many elements" ({
|
(it "makes a list of many elements" ({
|
||||||
actual = list ''
|
actual = list ''
|
||||||
- something
|
- something
|
||||||
- something else
|
- something else
|
||||||
|
@ -48,14 +47,28 @@ in with md; [
|
||||||
expected = {
|
expected = {
|
||||||
matched = true;
|
matched = true;
|
||||||
block = elems.List [
|
block = elems.List [
|
||||||
''
|
"something"
|
||||||
something
|
"something else"
|
||||||
''
|
|
||||||
''
|
|
||||||
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" ({
|
(it "matches a list with no whitespace around" ({
|
||||||
|
@ -65,12 +78,11 @@ in with md; [
|
||||||
expected = {
|
expected = {
|
||||||
matched = true;
|
matched = true;
|
||||||
block = elems.List [
|
block = elems.List [
|
||||||
''
|
"something"
|
||||||
something
|
|
||||||
''
|
|
||||||
"something else"
|
"something else"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
asJSON = true;
|
||||||
}))
|
}))
|
||||||
|
|
||||||
(it "doesnt match not a list" (let str = "blah blah";
|
(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" ({
|
(it "finds surrounded parts" ({
|
||||||
actual = replace (wrap "\\*\\*") elems.strong ''
|
actual = replace (wrap "\\*\\*") elems.strong ''
|
||||||
this text **may** contain **bold** words inside it.
|
this text **may** contain **bold** words inside it.
|
||||||
|
|
Loading…
Reference in a new issue