Skip to content

Commit

Permalink
fixed handling of single line code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Kshitij-Katiyar committed Jan 27, 2025
1 parent 7f89a5b commit 14cbdc0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
17 changes: 9 additions & 8 deletions server/webhook_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,16 +422,17 @@ func preProcessText(jiraMarkdownString string) string {
content := langSpecificBlock[contentStartIndex:endIndex]

lines := strings.Split(content, "\n")

if len(lines) == 1 {
return "`" + lines[0] + "`"
}

for i := range lines {
if lines[i] != "" {
lines[i] = "`" + lines[i] + "`"
}
}

if len(lines) == 1 {
return "`" + lines[0] + "`"
}

return "\n" + strings.Join(lines, "\n") + "\n"
})

Expand All @@ -447,6 +448,10 @@ func preProcessText(jiraMarkdownString string) string {

lines := strings.Split(content, "\n")

if len(lines) == 1 {
return "`" + lines[0] + "`"
}

if len(lines) > 0 {
lines[0] = "`" + lines[0] + "`\n"
}
Expand All @@ -461,10 +466,6 @@ func preProcessText(jiraMarkdownString string) string {
lines[len(lines)-1] = "`" + strings.TrimSuffix(lines[len(lines)-1], "{noformat}") + "`"
}

if len(lines) == 1 {
return "`" + lines[0] + "`"
}

return "\n" + strings.Join(lines, "") + "\n"
})

Expand Down
4 changes: 2 additions & 2 deletions server/webhook_parser_misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ non-numbered list text
},
"Code block formatting": {
input: "{code:go}fruit := \"APPLE\"{code}",
expectedOutput: "``fruit := \"APPLE\"``",
expectedOutput: "`fruit := \"APPLE\"`",
},
"Bullet list formatting": {
input: `* BULLET LIST ROW 1
Expand Down Expand Up @@ -206,7 +206,7 @@ h6. HEADING 6`,
},
"No-format block": {
input: "{noformat}This is not formatted{noformat}",
expectedOutput: "``This is not formatted`\n`",
expectedOutput: "`This is not formatted`",
},
"Double curly block": {
input: "{{This is a code block}}",
Expand Down

0 comments on commit 14cbdc0

Please sign in to comment.