package importer import ( "strings" "testing" ) func TestToMarkdown(t *testing.T) { for _, c := range []struct{ name, in, want string }{ {"paragraphs and inline", `

Some bold, italic and code with a link.

Second.

`, "Some **bold**, *italic* and `code` with a [link](/about/).\n\nSecond.\n"}, {"headings and rule", `

Title

Text


Sub title

`, "## Title\n\nText\n\n---\n\n### Sub *title*\n"}, {"nested lists", `
  1. Three
  2. Four

`, "- One\n- Two\n - Two a\n\n3. Three\n4. Four\n"}, {"quote", `

Said this.

And that.

`, "> Said *this*.\n>\n> And that.\n"}, {"code block", `
fmt.Println("a ` + "```" + ` b")
`, "````go\nfmt.Println(\"a ``` b\")\n````\n"}, {"figure", `
A dock
At dawn
`, "![A dock](https://ex.org/a.jpg)\n\n*At dawn*\n"}, {"escaping", `

1. Not a list, a *star*, snake_case and _edge_ [brackets]

`, "1\\. Not a list, a \\*star\\*, snake_case and \\_edge\\_ \\[brackets\\]\n"}, {"break and strike", `

Line one
line two gone

`, "Line one\\\nline two ~~gone~~\n"}, {"simple table", `
PlanPrice
Basic$5
`, "| Plan | Price |\n| --- | --- |\n| Basic | $5 |\n"}, {"block comments ignored", "\n

Hi

\n", "Hi\n"}, } { got := ToMarkdown(c.in) if got.Markdown != c.want || len(got.Lossy) != 0 { t.Errorf("%s:\ngot %q (lossy %v)\nwant %q", c.name, got.Markdown, got.Lossy, c.want) } } } func TestLossy(t *testing.T) { for _, c := range []struct{ in, why string }{ {`
`, "an embed"}, {`

a

`, "a layout block (wp-block-columns)"}, {`
a
`, "a table with merged or complex cells"}, {`

Red

`, "inline styles"}, {`

E = mc2

`, "superscript"}, } { got := ToMarkdown(c.in) if !strings.Contains(strings.Join(got.Lossy, ","), c.why) { t.Errorf("%s: lossy %v, want %q", c.in, got.Lossy, c.why) } } } func TestSafeImportPaths(t *testing.T) { for in, want := range map[string]string{"../../x": "x", "/a//b/": "a/b", `..\..\etc`: "etc", "news/2026": "news/2026"} { if got := safeDir(in); got != want { t.Errorf("safeDir(%q) = %q, want %q", in, got, want) } } if s := slugify("../../../x/README"); strings.Contains(s, "/") || strings.Contains(s, "..") { t.Errorf("slugify kept a path: %q", s) } if s := slugify("Café Ñandú 日本"); s != "café-ñandú-日本" { t.Errorf("letters lost: %q", s) } }