// SPDX-License-Identifier: AGPL-3.0-or-later package convert import ( "strings" "testing" ) func colTypes(doc Node) []string { var out []string for _, n := range doc.Content { out = append(out, n.Type) } return out } func TestColumnsRoundTripThroughHTML(t *testing.T) { doc := Node{Type: "doc", Content: []Node{{Type: "columns", Content: []Node{ {Type: "column", Attrs: map[string]any{"width": 70.0}, Content: []Node{cpara("Left")}}, {Type: "column", Attrs: map[string]any{"width": 30.0}, Content: []Node{cpara("Right")}}, }}}} out := HTML(doc, Options{}) if !strings.Contains(out, `data-type="columns"`) || !strings.Contains(out, `data-width="70"`) { t.Fatalf("html: %s", out) } back, err := FromHTML(out) if err != nil { t.Fatal(err) } if got := colTypes(back); len(got) != 1 || got[0] != "columns" { t.Fatalf("types: %v", got) } row := back.Content[0] if len(row.Content) != 2 || columnWidth(row.Content[0]) != 70 || PlainText(row.Content[1]) != "Right" { t.Fatalf("row: %+v", row) } } func TestColumnsFlattenInMarkdown(t *testing.T) { doc := Node{Type: "doc", Content: []Node{{Type: "columns", Content: []Node{ {Type: "column", Content: []Node{cpara("Left")}}, {Type: "column", Content: []Node{cpara("Right")}}, }}}} md := Markdown(doc, Options{}) if !strings.Contains(md, "Left") || !strings.Contains(md, "Right") || strings.Index(md, "Left") > strings.Index(md, "Right") { t.Fatalf("markdown: %q", md) } } func TestNotionAndConfluenceColumns(t *testing.T) { notion := `
A
B
Only