remove old doc func and fix md lists
This commit is contained in:
parent
93799cac12
commit
63f1c014af
12
flake.nix
12
flake.nix
|
@ -29,9 +29,10 @@
|
||||||
underblue = nixite.style.component blue "under" {
|
underblue = nixite.style.component blue "under" {
|
||||||
style = {text-decoration = "underline";};
|
style = {text-decoration = "underline";};
|
||||||
};
|
};
|
||||||
in (Doc {} [
|
in (
|
||||||
[(title "Nixite")]
|
nixite.html.document {
|
||||||
(main [
|
head = [(title "Nixite")];
|
||||||
|
body = main [
|
||||||
(a {href = nixite.site.link readme;} "Readme")
|
(a {href = nixite.site.link readme;} "Readme")
|
||||||
(a "/blog" "blog")
|
(a "/blog" "blog")
|
||||||
(List {} ["item 1" "item 2" "item 3"])
|
(List {} ["item 1" "item 2" "item 3"])
|
||||||
|
@ -41,8 +42,9 @@
|
||||||
"isn't it"
|
"isn't it"
|
||||||
(underblue {onclick = "alert(1)";} "great!")
|
(underblue {onclick = "alert(1)";} "great!")
|
||||||
])
|
])
|
||||||
])
|
];
|
||||||
]);
|
}
|
||||||
|
);
|
||||||
blog = nixite.md.readDir ./testing/blog;
|
blog = nixite.md.readDir ./testing/blog;
|
||||||
};
|
};
|
||||||
site =
|
site =
|
||||||
|
|
|
@ -143,14 +143,6 @@ in {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
Doc = params: child:
|
|
||||||
assert builtins.isList child;
|
|
||||||
assert builtins.length child == 2;
|
|
||||||
assert builtins.isList (builtins.elemAt child 0);
|
|
||||||
html.tag "html" ({lang = "en";} // params) [
|
|
||||||
(html.tag "head" {} (builtins.elemAt child 0))
|
|
||||||
(html.tag "body" {} (builtins.elemAt child 1))
|
|
||||||
];
|
|
||||||
Stylesheet = params:
|
Stylesheet = params:
|
||||||
html.tag "link" ({
|
html.tag "link" ({
|
||||||
rel = "stylesheet";
|
rel = "stylesheet";
|
||||||
|
|
|
@ -13,7 +13,7 @@ in rec {
|
||||||
if builtins.isString elem
|
if builtins.isString elem
|
||||||
then elem
|
then elem
|
||||||
else if builtins.isList elem
|
else if builtins.isList elem
|
||||||
then builtins.toString (map toHTML elem)
|
then builtins.concatStringsSep "" (map toHTML elem)
|
||||||
else "<${elem.tag} ${writeAttrs elem.attrs or {}}>${
|
else "<${elem.tag} ${writeAttrs elem.attrs or {}}>${
|
||||||
toHTML elem.child or ""
|
toHTML elem.child or ""
|
||||||
}</${elem.tag}>";
|
}</${elem.tag}>";
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
let
|
let
|
||||||
elems = import ./elems.nix;
|
elems = import ./elems.nix;
|
||||||
|
html = import ./html.nix;
|
||||||
in rec {
|
in rec {
|
||||||
processMd = md:
|
processMd = md:
|
||||||
if builtins.isPath md
|
if builtins.isPath md
|
||||||
|
@ -30,7 +31,10 @@ in rec {
|
||||||
readDir = root: recFixAppendix (recReadMd root);
|
readDir = root: recFixAppendix (recReadMd root);
|
||||||
|
|
||||||
mdToPage = md:
|
mdToPage = md:
|
||||||
elems.Doc {} [[(elems.title {} "markdown file")] (processMd md)];
|
html.document {
|
||||||
|
head = [];
|
||||||
|
body = elems.main (elems.article (processMd md));
|
||||||
|
};
|
||||||
|
|
||||||
splitList = block:
|
splitList = block:
|
||||||
map listItem (builtins.filter (s: builtins.isString s && s != "")
|
map listItem (builtins.filter (s: builtins.isString s && s != "")
|
||||||
|
@ -53,26 +57,29 @@ in rec {
|
||||||
content
|
content
|
||||||
];
|
];
|
||||||
|
|
||||||
replace = regex: apply: block: (let
|
replace = regex: apply: block:
|
||||||
|
assert builtins.isString block; (let
|
||||||
m = builtins.match regex block;
|
m = builtins.match regex block;
|
||||||
before = let
|
before = builtins.elemAt m 0;
|
||||||
v = builtins.elemAt m 0;
|
|
||||||
in
|
|
||||||
if v == null
|
|
||||||
then ""
|
|
||||||
else v;
|
|
||||||
after = toString (builtins.elemAt m (matchCount - 1));
|
after = toString (builtins.elemAt m (matchCount - 1));
|
||||||
matchCount = builtins.length m;
|
matchCount = builtins.length m;
|
||||||
in
|
in
|
||||||
if m == null
|
if m == null
|
||||||
then block
|
then block
|
||||||
else (replace regex apply before) + (apply m) + after);
|
else
|
||||||
|
(
|
||||||
|
if before == null
|
||||||
|
then ""
|
||||||
|
else replace regex apply before
|
||||||
|
)
|
||||||
|
+ (apply m)
|
||||||
|
+ after);
|
||||||
|
|
||||||
rule = matcher: apply: blocks:
|
rule = matcher: apply: blocks:
|
||||||
map (b:
|
map (block:
|
||||||
if builtins.isString b
|
if builtins.isString block
|
||||||
then replace matcher apply b
|
then replace matcher apply block
|
||||||
else b)
|
else block)
|
||||||
blocks;
|
blocks;
|
||||||
|
|
||||||
applyRules = i: rules: input: let
|
applyRules = i: rules: input: let
|
||||||
|
@ -117,14 +124,14 @@ in rec {
|
||||||
(basicRule (containsBreak "<(${linkmatcher})>") (m: elems.a m m))
|
(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:
|
l: (elems.ul (basicRule "(.*\n)?- ([^\n]+)\n(.*)" (m:
|
||||||
elems.li (basicRule "()\\[(.)] (.*)" (check:
|
elems.li (basicRule "()\\[(.)] (.*)" (check:
|
||||||
elems.input {
|
elems.input {
|
||||||
type = "checkbox";
|
type = "checkbox";
|
||||||
checked = check != " ";
|
checked = check != " ";
|
||||||
disabled = true;
|
disabled = true;
|
||||||
}) [m])) [(builtins.elemAt l 2)]))
|
}) [m])) [(builtins.elemAt l 4)]))
|
||||||
);
|
);
|
||||||
|
|
||||||
linkmatcher = "[-[:alnum:].%?&#=:/]+";
|
linkmatcher = "[-[:alnum:].%?&#=:/]+";
|
||||||
|
|
|
@ -80,15 +80,6 @@ in
|
||||||
actual = List {} ["foo" "bar" "baz"];
|
actual = List {} ["foo" "bar" "baz"];
|
||||||
asString = true;
|
asString = true;
|
||||||
})
|
})
|
||||||
(it "makes an html doc" {
|
|
||||||
expected = html.tag "html" {
|
|
||||||
__child = "";
|
|
||||||
class = [];
|
|
||||||
lang = "en";
|
|
||||||
} [(html.tag "head" {} ["foo"]) (html.tag "body" {} "bar")];
|
|
||||||
actual = Doc {} [["foo"] "bar"];
|
|
||||||
asString = true;
|
|
||||||
})
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
md = import ../nixite/md.nix;
|
md = import ../nixite/md.nix;
|
||||||
|
html = import ../nixite/html.nix;
|
||||||
elems = import ../nixite/elems.nix;
|
elems = import ../nixite/elems.nix;
|
||||||
in
|
in
|
||||||
with md; [
|
with md; [
|
||||||
|
@ -16,6 +17,7 @@ in
|
||||||
''
|
''
|
||||||
];
|
];
|
||||||
expected = [(elems.List ["something"])];
|
expected = [(elems.List ["something"])];
|
||||||
|
asJSON = true;
|
||||||
})
|
})
|
||||||
|
|
||||||
(it "makes a list of many elements" {
|
(it "makes a list of many elements" {
|
||||||
|
@ -26,6 +28,7 @@ in
|
||||||
''
|
''
|
||||||
];
|
];
|
||||||
expected = [(elems.List ["something" "something else"])];
|
expected = [(elems.List ["something" "something else"])];
|
||||||
|
asJSON = true;
|
||||||
})
|
})
|
||||||
|
|
||||||
(it "makes a list of many checkboxes" {
|
(it "makes a list of many checkboxes" {
|
||||||
|
@ -55,15 +58,7 @@ in
|
||||||
]
|
]
|
||||||
])
|
])
|
||||||
];
|
];
|
||||||
})
|
asJSON = true;
|
||||||
|
|
||||||
(it "matches a list with no whitespace around" {
|
|
||||||
actual = list [
|
|
||||||
''
|
|
||||||
- something
|
|
||||||
- something else''
|
|
||||||
];
|
|
||||||
expected = [(elems.List ["something" "something else"])];
|
|
||||||
})
|
})
|
||||||
|
|
||||||
(it "doesnt match not a list" (let
|
(it "doesnt match not a list" (let
|
||||||
|
@ -80,16 +75,16 @@ in
|
||||||
actual = processStr ''
|
actual = processStr ''
|
||||||
this text **may** *or may not* contain **bold** words *inside* it.
|
this text **may** *or may not* contain **bold** words *inside* it.
|
||||||
'';
|
'';
|
||||||
expected = elems.p [
|
expected = [(elems.p [
|
||||||
"this text "
|
"this text "
|
||||||
(elems.strong "may")
|
(elems.strong "may") " "
|
||||||
(elems.em "or may not")
|
(elems.em "or may not")
|
||||||
" contain "
|
" contain "
|
||||||
(elems.strong "bold")
|
(elems.strong "bold")
|
||||||
" words "
|
" words "
|
||||||
(elems.em "inside")
|
(elems.em "inside")
|
||||||
" it."
|
" it."
|
||||||
];
|
])];
|
||||||
asString = true;
|
asString = true;
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -119,9 +114,25 @@ in
|
||||||
(
|
(
|
||||||
describe "mdToPage" [
|
describe "mdToPage" [
|
||||||
(it "converts markdown to a page" {
|
(it "converts markdown to a page" {
|
||||||
actual = toString (mdToPage ./blog/index.md) + "\n\n"; # inflation
|
|
||||||
expected = builtins.readFile ./out/index.html;
|
|
||||||
asString = true;
|
asString = true;
|
||||||
|
actual = mdToPage ''
|
||||||
|
# Markdown
|
||||||
|
|
||||||
|
This is *markdown*!
|
||||||
|
'';
|
||||||
|
expected = html.document {
|
||||||
|
head = [];
|
||||||
|
body = [
|
||||||
|
(elems.main (elems.article [
|
||||||
|
(elems.h1 "Markdown")
|
||||||
|
(elems.p [
|
||||||
|
"This is"
|
||||||
|
(elems.em "markdown")
|
||||||
|
"!"
|
||||||
|
])
|
||||||
|
]))
|
||||||
|
];
|
||||||
|
};
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue