From e65c3ffe6b56c50ecc23a6a9fadd0d33d7cadbe0 Mon Sep 17 00:00:00 2001 From: kolaente Date: Sat, 9 Mar 2024 09:31:50 +0100 Subject: [PATCH] fix(migration): convert trello card descriptions from markdown to html --- pkg/modules/migration/trello/trello.go | 19 ++++++++++++++++++- pkg/modules/migration/trello/trello_test.go | 4 ++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/pkg/modules/migration/trello/trello.go b/pkg/modules/migration/trello/trello.go index a286f3b32..0ae4edd8a 100644 --- a/pkg/modules/migration/trello/trello.go +++ b/pkg/modules/migration/trello/trello.go @@ -17,6 +17,8 @@ package trello import ( + "bytes" + "code.vikunja.io/api/pkg/config" "code.vikunja.io/api/pkg/files" "code.vikunja.io/api/pkg/log" @@ -24,6 +26,7 @@ import ( "code.vikunja.io/api/pkg/modules/migration" "code.vikunja.io/api/pkg/user" "github.com/adlio/trello" + "github.com/yuin/goldmark" ) // Migration represents the trello migration struct @@ -160,6 +163,16 @@ func getTrelloData(token string) (trelloData []*trello.Board, err error) { return } +func convertMarkdownToHTML(input string) (output string, err error) { + var buf bytes.Buffer + err = goldmark.Convert([]byte(input), &buf) + if err != nil { + return + } + //#nosec - we are not responsible to escape this as we don't know the context where it is used + return buf.String(), nil +} + // Converts all previously obtained data from trello into the vikunja format. // `trelloData` should contain all boards with their projects and cards respectively. func convertTrelloDataToVikunja(trelloData []*trello.Board, token string) (fullVikunjaHierachie []*models.ProjectWithTasksAndBuckets, err error) { @@ -220,11 +233,15 @@ func convertTrelloDataToVikunja(trelloData []*trello.Board, token string) (fullV // The usual stuff: Title, description, position, bucket id task := &models.Task{ Title: card.Name, - Description: card.Desc, KanbanPosition: card.Pos, BucketID: bucketID, } + task.Description, err = convertMarkdownToHTML(card.Desc) + if err != nil { + return nil, err + } + if card.Due != nil { task.DueDate = *card.Due } diff --git a/pkg/modules/migration/trello/trello_test.go b/pkg/modules/migration/trello/trello_test.go index febc38c2b..020ab5399 100644 --- a/pkg/modules/migration/trello/trello_test.go +++ b/pkg/modules/migration/trello/trello_test.go @@ -52,7 +52,7 @@ func TestConvertTrelloToVikunja(t *testing.T) { Cards: []*trello.Card{ { Name: "Test Card 1", - Desc: "Card Description", + Desc: "Card Description **bold**", Pos: 123, Due: &time1, Labels: []*trello.Label{ @@ -218,7 +218,7 @@ func TestConvertTrelloToVikunja(t *testing.T) { { Task: models.Task{ Title: "Test Card 1", - Description: "Card Description", + Description: "

Card Description bold

\n", BucketID: 1, KanbanPosition: 123, DueDate: time1,