// SPDX-License-Identifier: AGPL-3.0-or-later package convert import ( "archive/zip" "bytes" "encoding/xml" "errors" "io" "strings" "testing" ) const phaseA = `{"type":"doc","content":[ {"type":"heading","attrs":{"level":5,"textAlign":"center"},"content":[{"type":"text","text":"Small"}]}, {"type":"paragraph","attrs":{"textAlign":"right"},"content":[ {"type":"text","text":"red","marks":[{"type":"textColor","attrs":{"color":"red"}}]}, {"type":"text","text":" and "}, {"type":"text","text":"marked","marks":[{"type":"highlight","attrs":{"color":"green"}}]}]}, {"type":"taskList","content":[ {"type":"taskItem","attrs":{"checked":true},"content":[{"type":"paragraph","content":[{"type":"text","text":"done"}]}]}, {"type":"taskItem","attrs":{"checked":false},"content":[{"type":"paragraph","content":[{"type":"text","text":"todo"}]}]}]}, {"type":"callout","attrs":{"emoji":"🔥","color":"red"},"content":[{"type":"paragraph","content":[{"type":"text","text":"Careful"}]}]}, {"type":"callout","attrs":{"emoji":"💡","color":"blue"},"content":[{"type":"paragraph","content":[{"type":"text","text":"Plain"}]}]}, {"type":"table","content":[ {"type":"tableRow","content":[ {"type":"tableHeader","content":[{"type":"paragraph","content":[{"type":"text","text":"Name"}]}]}, {"type":"tableHeader","content":[{"type":"paragraph","content":[{"type":"text","text":"Role"}]}]}]}, {"type":"tableRow","content":[ {"type":"tableCell","content":[{"type":"paragraph","content":[{"type":"text","text":"Ada | A"}]}]}, {"type":"tableCell","attrs":{"colspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Lead"}]},{"type":"paragraph","content":[{"type":"text","text":"and more"}]}]}]}]} ]}` func TestPhaseABlocksMarkdown(t *testing.T) { md := Markdown(mustParse(t, phaseA), Options{}) for _, want := range []string{ "##### Small\n", "- [x] done\n- [ ] todo\n", "> [!CAUTION]\n> 🔥 Careful\n", "> [!NOTE]\n> Plain\n", "| Name | Role |\n| --- | --- |\n| Ada \\| A | Lead and more |\n", } { if !strings.Contains(md, want) { t.Errorf("markdown lacks %q:\n%s", want, md) } } // And back: the same kinds of blocks come out again. doc, err := FromMarkdown(md) if err != nil { t.Fatal(err) } j := asJSON(t, doc) for _, want := range []string{ `"level":5`, `{"type":"taskItem","attrs":{"checked":true}`, `{"type":"callout","attrs":{"color":"red","emoji":"🔥"},"content":[{"type":"paragraph","content":[{"type":"text","text":"Careful"}]}]}`, `{"type":"callout","attrs":{"color":"blue","emoji":"💡"}`, `"type":"tableHeader"`, `"text":"Ada | A"`, } { if !strings.Contains(j, want) { t.Errorf("import lacks %s:\n%s", want, j) } } } func TestPhaseABlocksHTML(t *testing.T) { h := HTML(mustParse(t, phaseA), Options{}) for _, want := range []string{ `
Small
`, `

red and

done

`, `