2023-12-31 00:24:48 +00:00
|
|
|
let
|
|
|
|
md = import ../nixite/md.nix;
|
|
|
|
elems = import ../nixite/elems.nix;
|
|
|
|
it = import ./it.nix;
|
2023-12-31 21:33:42 +00:00
|
|
|
in with md; [
|
2023-12-31 00:24:48 +00:00
|
|
|
|
2024-01-01 13:48:26 +00:00
|
|
|
(it "gets md heading" {
|
2024-01-01 14:06:54 +00:00
|
|
|
actual = mdBlock "# title of the page";
|
2024-01-01 13:48:26 +00:00
|
|
|
expected = elems.h1 "title of the page";
|
|
|
|
})
|
|
|
|
|
|
|
|
(it "gets md heading 2" {
|
2024-01-01 14:06:54 +00:00
|
|
|
actual = mdBlock "## a subheading";
|
2024-01-01 13:48:26 +00:00
|
|
|
expected = elems.h2 "a subheading";
|
|
|
|
})
|
|
|
|
|
|
|
|
(it "limits to 6 #" {
|
2024-01-01 14:06:54 +00:00
|
|
|
actual = mdBlock "######## super ultra tiny heading";
|
2024-01-01 13:48:26 +00:00
|
|
|
expected = elems.h6 "super ultra tiny heading";
|
|
|
|
})
|
2023-12-31 00:24:48 +00:00
|
|
|
|
2024-01-01 14:06:54 +00:00
|
|
|
(it "makes a code block" (
|
|
|
|
let code = ''
|
|
|
|
this is my code
|
|
|
|
''; in {
|
|
|
|
actual = mdBlock ''
|
|
|
|
```${code}```'';
|
|
|
|
expected = elems.code code;
|
|
|
|
}))
|
|
|
|
|
2023-12-31 21:33:42 +00:00
|
|
|
(it "processes md block" {
|
|
|
|
actual = readMd ''
|
|
|
|
# foo bar
|
2023-12-31 00:24:48 +00:00
|
|
|
|
2023-12-31 21:33:42 +00:00
|
|
|
lorem ipsum
|
|
|
|
'';
|
|
|
|
expected = [
|
2024-01-01 06:33:57 +00:00
|
|
|
(elems.h1 { } "foo bar")
|
2023-12-31 21:33:42 +00:00
|
|
|
""
|
|
|
|
(elems.p { } ''
|
2023-12-31 00:24:48 +00:00
|
|
|
lorem ipsum
|
2023-12-31 21:33:42 +00:00
|
|
|
'')
|
|
|
|
];
|
|
|
|
asString = true;
|
|
|
|
})
|
2023-12-31 10:33:05 +00:00
|
|
|
|
2023-12-31 21:33:42 +00:00
|
|
|
(it "can fix file appendixes" {
|
|
|
|
actual = fixAppendix "index.md";
|
|
|
|
expected = "index.html";
|
|
|
|
})
|
2023-12-31 10:33:05 +00:00
|
|
|
|
2024-01-01 06:33:57 +00:00
|
|
|
(it "converts markdown to a page" {
|
|
|
|
actual = mdToPage ./blog/index.md;
|
|
|
|
expected = ''
|
|
|
|
<html lang="en"><head ><title >markdown file</title></head> <body ><h1 >yeee</h1> <p >ye</p> <p >&</p> <p ><a href="dir">dir</a>
|
|
|
|
<a href="/">home</a></p> <p ></p></body></html>'';
|
|
|
|
asString = true;
|
|
|
|
})
|
|
|
|
|
2023-12-31 21:33:42 +00:00
|
|
|
(it "recursively reads dir" {
|
|
|
|
actual = recReadMd ./blog;
|
|
|
|
expected = {
|
|
|
|
"index.md" = mdToPage ./blog/index.md;
|
|
|
|
"dir" = { "index.md" = mdToPage ./blog/dir/index.md; };
|
|
|
|
};
|
|
|
|
asJSON = true;
|
|
|
|
})
|
2023-12-31 10:33:05 +00:00
|
|
|
|
2023-12-31 21:33:42 +00:00
|
|
|
(it "recursively fixes filename" {
|
|
|
|
actual = recFixAppendix {
|
|
|
|
"index.md" = "something";
|
|
|
|
dir = { "index.md" = "something else"; };
|
|
|
|
};
|
|
|
|
expected = {
|
|
|
|
"index.html" = "something";
|
|
|
|
dir = { "index.html" = "something else"; };
|
|
|
|
};
|
|
|
|
})
|
2023-12-31 10:33:05 +00:00
|
|
|
|
2023-12-31 21:33:42 +00:00
|
|
|
(it "recursively translates md to html" {
|
|
|
|
actual = builtins.toJSON (readDir ./blog);
|
|
|
|
expected = builtins.toJSON {
|
|
|
|
"index.html" = mdToPage ./blog/index.md;
|
|
|
|
"dir" = { "index.html" = mdToPage ./blog/dir/index.md; };
|
|
|
|
};
|
|
|
|
})
|
|
|
|
]
|