Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rickschubert committed Jun 21, 2020
1 parent ba524a2 commit d7f0f3a
Showing 1 changed file with 39 additions and 26 deletions.
65 changes: 39 additions & 26 deletions jira/jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,35 +113,48 @@ func splitPlainTextDescriptionIntoJiraApiObjects(plainTextDescription string) []
}
}

func makeParagraphLinksClickable(paragraph paragraphContent) []paragraphContent {
var newParagraphContents []paragraphContent
linksInParagraph := utils.SplitTextOnLinks(paragraph.Text)
for _, text := range linksInParagraph {
var paraContent paragraphContent
if text.IsLink {
paraContent = paragraphContent{
Type: "text",
Text: text.Text,
Marks: []mark{
{
Type: "link",
Attrs: Attr{
Href: text.Text,
},
},
},
}
} else {
paraContent = paragraphContent{
Type: "text",
Text: text.Text,
}
}
newParagraphContents = append(newParagraphContents, paraContent)
}
return newParagraphContents
}

func isParagraphHardBreak(paragraph paragraphContent) bool {
return paragraph.Type == "hardBreak"
}

func linkifyContentBlock(cont content) content {
var newParagraphContents []paragraphContent
for _, paragraph := range cont.Content {
if paragraph.Type == "hardBreak" {
newParagraphContents = append(newParagraphContents, paragraph)
for _, plainParagraph := range cont.Content {
if isParagraphHardBreak(plainParagraph) {
newParagraphContents = append(newParagraphContents, plainParagraph)
} else {
linksInParagraph := utils.SplitTextOnLinks(paragraph.Text)
for _, text := range linksInParagraph {
var paraContent paragraphContent
if text.IsLink {
paraContent = paragraphContent{
Type: "text",
Text: text.Text,
Marks: []mark{
{
Type: "link",
Attrs: Attr{
Href: text.Text,
},
},
},
}
} else {
paraContent = paragraphContent{
Type: "text",
Text: text.Text,
}
}
newParagraphContents = append(newParagraphContents, paraContent)
paragraphWithClickableLinks := makeParagraphLinksClickable(plainParagraph)
for _, paragraph := range paragraphWithClickableLinks {
newParagraphContents = append(newParagraphContents, paragraph)
}
}
}
Expand Down

0 comments on commit d7f0f3a

Please sign in to comment.