rework markdown processor
This commit is contained in:
parent
9421a0a910
commit
d04a6cc679
4 changed files with 105 additions and 145 deletions
|
@ -4,30 +4,6 @@ let
|
|||
it = import ./it.nix;
|
||||
in with md; [
|
||||
|
||||
(it "gets md heading" {
|
||||
actual = mdBlock "# title of the page";
|
||||
expected = elems.h1 "title of the page";
|
||||
})
|
||||
|
||||
(it "gets md heading 2" {
|
||||
actual = mdBlock "## a subheading";
|
||||
expected = elems.h2 "a subheading";
|
||||
})
|
||||
|
||||
(it "limits to 6 #" {
|
||||
actual = mdBlock "######## 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 "matches a list of one element" ({
|
||||
actual = list ''
|
||||
- something
|
||||
|
@ -100,31 +76,11 @@ in with md; [
|
|||
};
|
||||
}))
|
||||
|
||||
(it "finds surrounded parts" ({
|
||||
actual = replace (wrap "\\*\\*") elems.strong ''
|
||||
this text **may** contain **bold** words inside it.
|
||||
(it "processes whole string with all rules" ({
|
||||
actual = processStr ''
|
||||
this text **may** *or may not* contain **bold** words *inside* it.
|
||||
'';
|
||||
expected = [
|
||||
"this text"
|
||||
(elems.strong "may")
|
||||
"contain"
|
||||
(elems.strong "bold")
|
||||
''
|
||||
words inside it.
|
||||
''
|
||||
];
|
||||
asString = true;
|
||||
}))
|
||||
|
||||
(it "surrounds in list of elems" ({
|
||||
actual = rule (wrap "\\*") elems.em [
|
||||
"this text"
|
||||
(elems.strong "may")
|
||||
"*or may not* contain"
|
||||
(elems.strong "bold")
|
||||
"words *inside* it."
|
||||
];
|
||||
expected = [
|
||||
expected = (elems.p [
|
||||
"this text"
|
||||
(elems.strong "may")
|
||||
(elems.em "or may not")
|
||||
|
@ -133,42 +89,18 @@ in with md; [
|
|||
"words"
|
||||
(elems.em "inside")
|
||||
"it."
|
||||
];
|
||||
]);
|
||||
asString = true;
|
||||
}))
|
||||
|
||||
(it "processes whole string with all rules" ({
|
||||
actual = processStr ''
|
||||
this text **may** *or may not* contain **bold** words *inside* it.
|
||||
'';
|
||||
expected = [
|
||||
"this text"
|
||||
(elems.strong "may")
|
||||
(elems.em "or may not")
|
||||
"contain"
|
||||
(elems.strong "bold")
|
||||
"words"
|
||||
(elems.em "inside")
|
||||
''
|
||||
it.
|
||||
''
|
||||
];
|
||||
asString = true;
|
||||
}))
|
||||
|
||||
(it "processes md block" {
|
||||
(it "makes paragraphs" {
|
||||
actual = readMd ''
|
||||
# foo bar
|
||||
|
||||
lorem ipsum
|
||||
dolor sit
|
||||
|
||||
foo bar
|
||||
'';
|
||||
expected = [
|
||||
(elems.h1 { } "foo bar")
|
||||
""
|
||||
(elems.p { } ''
|
||||
lorem ipsum
|
||||
'')
|
||||
];
|
||||
expected = "<p >lorem ipsum\ndolor sit\n</p><p >foo bar</p>";
|
||||
asString = true;
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue