import { assertEquals } from "testing/asserts.ts";
import { HtmlStrRenderer } from "../ren/html_str.ts";
import { MarkdownParser } from "./md.ts";
const ren = new HtmlStrRenderer();
Deno.test({
name: "should skip new line character",
fn: () => {
const par = new MarkdownParser();
assertEquals(ren.render(par.parse("\n")), "");
assertEquals(ren.render(par.parse("\r\n")), "");
assertEquals(ren.render(par.parse("\n\r\n")), "");
},
});
Deno.test({
name: "should parse empty ATX header",
fn: () => {
const par = new MarkdownParser();
const res = par.parse("#");
assertEquals(ren.render(res), "
");
},
});
Deno.test({
name: "should parse ATX header with text",
fn: () => {
const par = new MarkdownParser();
assertEquals(ren.render(par.parse("# hello")), "hello
");
assertEquals(ren.render(par.parse("# hello#")), "hello#
");
},
});
Deno.test({
name: "should parse ATX header with specific level",
fn: () => {
const par = new MarkdownParser();
assertEquals(ren.render(par.parse("# hello")), "hello
");
assertEquals(ren.render(par.parse("## hello")), "hello
");
assertEquals(ren.render(par.parse("### hello")), "hello
");
assertEquals(ren.render(par.parse("#### hello")), "hello
");
assertEquals(ren.render(par.parse("##### hello")), "hello
");
assertEquals(ren.render(par.parse("###### hello")), "hello
");
},
});
Deno.test({
name: "should parse ATX header if line contains additional spaces",
fn: () => {
const par = new MarkdownParser();
assertEquals(ren.render(par.parse(" # hello")), "hello
");
assertEquals(ren.render(par.parse(" # hello")), "hello
");
assertEquals(ren.render(par.parse(" # hello")), "hello
");
assertEquals(ren.render(par.parse("\n # hello")), "hello
");
assertEquals(ren.render(par.parse("\r\n # hello")), "hello
");
},
});
Deno.test({
name: "should parse ATX header with closing sequence",
fn: () => {
const par = new MarkdownParser();
assertEquals(ren.render(par.parse("# #")), "");
assertEquals(ren.render(par.parse("# hello #")), "hello
");
assertEquals(ren.render(par.parse("# hello #########")), "hello
");
assertEquals(ren.render(par.parse("# hello # ")), "hello
");
assertEquals(ren.render(par.parse("###### hello #")), "hello
");
},
});
Deno.test({
name: "should parse many headers with text",
fn: () => {
const par = new MarkdownParser();
const input = `\
# hello
## world
### this is
#### my world!`;
assertEquals(
ren.render(par.parse(input)),
"hello
world
this is
my world!
",
);
},
});