add md code block support (basic)
This commit is contained in:
parent
3ceb580768
commit
fafff120f9
|
@ -49,7 +49,7 @@ nix build .#raw
|
||||||
- [ ] checkboxes
|
- [ ] checkboxes
|
||||||
- [ ] images
|
- [ ] images
|
||||||
- [ ] links
|
- [ ] links
|
||||||
- [ ] codeblocks
|
- [X] codeblocks
|
||||||
- [ ] subscript
|
- [ ] subscript
|
||||||
- [ ] highlight
|
- [ ] highlight
|
||||||
- [ ] italics
|
- [ ] italics
|
||||||
|
|
|
@ -46,9 +46,22 @@ in rec {
|
||||||
|
|
||||||
mdBlock = block:
|
mdBlock = block:
|
||||||
let
|
let
|
||||||
m = heading block;
|
h = heading block;
|
||||||
h = if m == null then 0 else builtins.stringLength (builtins.elemAt m 0);
|
c = code block;
|
||||||
in if m == null then elems.p { } block else H h (builtins.elemAt m 1);
|
in (if h.matched then h.block else
|
||||||
|
if c.matched then c.block else
|
||||||
|
elems.p block);
|
||||||
|
|
||||||
heading = block: builtins.match "(#+) (.*)" block;
|
heading = block: let
|
||||||
|
m = builtins.match "(#+) (.*)" block;
|
||||||
|
l = builtins.stringLength (builtins.elemAt m 0);
|
||||||
|
in
|
||||||
|
if m == null then { matched = false; inherit block; }
|
||||||
|
else { matched = true; block = H l (builtins.elemAt m 1); };
|
||||||
|
|
||||||
|
code = block: let
|
||||||
|
m = builtins.match "(```)(.*)(```)" block;
|
||||||
|
in
|
||||||
|
if m == null then { matched = false; inherit block; }
|
||||||
|
else { matched = true; block = elems.code (builtins.elemAt m 1); };
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,23 +5,29 @@ let
|
||||||
in with md; [
|
in with md; [
|
||||||
|
|
||||||
(it "gets md heading" {
|
(it "gets md heading" {
|
||||||
actual = mdBlock ''
|
actual = mdBlock "# title of the page";
|
||||||
# title of the page'';
|
|
||||||
expected = elems.h1 "title of the page";
|
expected = elems.h1 "title of the page";
|
||||||
})
|
})
|
||||||
|
|
||||||
(it "gets md heading 2" {
|
(it "gets md heading 2" {
|
||||||
actual = mdBlock ''
|
actual = mdBlock "## a subheading";
|
||||||
## a subheading'';
|
|
||||||
expected = elems.h2 "a subheading";
|
expected = elems.h2 "a subheading";
|
||||||
})
|
})
|
||||||
|
|
||||||
(it "limits to 6 #" {
|
(it "limits to 6 #" {
|
||||||
actual = mdBlock ''
|
actual = mdBlock "######## super ultra tiny heading";
|
||||||
######## super ultra tiny heading'';
|
|
||||||
expected = elems.h6 "super ultra tiny heading";
|
expected = elems.h6 "super ultra tiny heading";
|
||||||
})
|
})
|
||||||
|
|
||||||
|
(it "makes a code block" (
|
||||||
|
let code = ''
|
||||||
|
this is my code
|
||||||
|
''; in {
|
||||||
|
actual = mdBlock ''
|
||||||
|
```${code}```'';
|
||||||
|
expected = elems.code code;
|
||||||
|
}))
|
||||||
|
|
||||||
(it "processes md block" {
|
(it "processes md block" {
|
||||||
actual = readMd ''
|
actual = readMd ''
|
||||||
# foo bar
|
# foo bar
|
||||||
|
|
Loading…
Reference in a new issue