package test import ( domainArticle "RenewCMS/internal/domain/article" "RenewCMS/internal/infrastructure/markdown" "testing" ) func TestJsonBlocksConverter(t *testing.T) { converter := markdown.NewConverter() paragraphA := `{"type":"paragraph","children":[{"type":"text","text":"a","marks":[]}]}` listOfA := `[{"type":"list","ordered":false,"items":[[` + paragraphA + `]]}]` examples := []struct { name, html, json string }{ {"h1", "
plain
", `[{"type":"paragraph","children":[{"type":"text","text":"plain","marks":[]}]}]`}, {"empty paragraph", "", `[{"type":"paragraph","children":[]}]`}, {"bold", "b
", `[{"type":"paragraph","children":[{"type":"text","text":"b","marks":[{"type":"bold"}]}]}]`}, {"italic", "i
", `[{"type":"paragraph","children":[{"type":"text","text":"i","marks":[{"type":"italic"}]}]}]`}, {"link", ``, `[{"type":"paragraph","children":[{"type":"text","text":"l","marks":[{"type":"link","href":"https://example.com/x"}]}]}]`}, {"nested marks outermost first", ``, `[{"type":"paragraph","children":[{"type":"text","text":"x","marks":[{"type":"link","href":"/a"},{"type":"bold"},{"type":"italic"}]}]}]`}, {"line break", "a
b
a
b
a
a
n
a
", `[{"type":"blockquote","children":[{"type":"paragraph","children":[{"type":"text","text":"q","marks":[]}]}]}]`}, {"code with language", `q
x := 1`, `[{"type":"code","language":"go","text":"x := 1"}]`},
{"code without language", "raw", `[{"type":"code","language":"","text":"raw"}]`},
{"rule", "
`, `[{"type":"image","src":"/static/uploadedImages/a.png","alt":"A"}]`},
{"image without alt", `
`, `[{"type":"image","src":"/static/uploadedImages/a.png","alt":""}]`},
{"image splits paragraph", `x
y
xy
`, `[{"type":"paragraph","children":[{"type":"text","text":"xy","marks":[]}]}]`}, {"inline code degrades", "use go test
ok
", `[{"type":"paragraph","children":[{"type":"text","text":"ok","marks":[]}]}]`}, {"empty html", "", `[]`}, {"centered paragraph", `a
`, `[{"type":"paragraph","align":"center","children":[{"type":"text","text":"a","marks":[]}]}]`}, {"right aligned heading", `a
`, `[{"type":"paragraph","align":"justify","children":[{"type":"text","text":"a","marks":[]}]}]`}, {"left alignment omitted", `a
`, `[` + paragraphA + `]`}, {"alignment skips the image inside a paragraph", `x
y