Skip to content

Commit

Permalink
[MM-1064]: Fixed issue of code block rendering in subscription post (#…
Browse files Browse the repository at this point in the history
…1151)

* [MM-1064]: Fixed issue of code block rendering in subscription post

* [MM-1064]: review fixes

* review fixes
  • Loading branch information
Kshitij-Katiyar authored Jan 27, 2025
1 parent d9214df commit 35925b4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions server/webhook_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ func preProcessText(jiraMarkdownString string) string {
linkRegex := regexp.MustCompile(`\[(.*?)\|([^|\]]+)(?:\|([^|\]]+))?\]`)
quoteRegex := regexp.MustCompile(`\{quote\}(.*?)\{quote\}`)
codeBlockRegex := regexp.MustCompile(`\{\{(.+?)\}\}`)
noFormatRegex := regexp.MustCompile(`\{noformat\}(.*?)\{noformat\}`)
doubleCurlyRegex := regexp.MustCompile(`\{\{(.*?)\}\}`)

// the below code converts lines starting with "#" into a numbered list. It increments the counter if consecutive lines are numbered,
// otherwise resets it to 1. The "#" is replaced with the corresponding number and period. Non-numbered lines are added unchanged.
Expand Down Expand Up @@ -403,6 +405,16 @@ func preProcessText(jiraMarkdownString string) string {
return "> " + quotedText
})

processedString = noFormatRegex.ReplaceAllStringFunc(processedString, func(noFormatBlock string) string {
content := noFormatBlock[strings.Index(noFormatBlock, "}")+1 : strings.LastIndex(noFormatBlock, "{noformat}")]
return fmt.Sprintf("`%s`", content)
})

processedString = doubleCurlyRegex.ReplaceAllStringFunc(processedString, func(match string) string {
content := match[2 : len(match)-2]
return fmt.Sprintf("`%s`", content)
})

return processedString
}

Expand Down
8 changes: 8 additions & 0 deletions server/webhook_parser_misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ h6. HEADING 6`,
input: "{quote}This is a quote{quote}",
expectedOutput: "> This is a quote",
},
"No-format block": {
input: "{noformat}This is not formatted{noformat}",
expectedOutput: "`This is not formatted`",
},
"Double curly block": {
input: "{{This is a code block}}",
expectedOutput: "`This is a code block`",
},
}

for name, tc := range tests {
Expand Down

0 comments on commit 35925b4

Please sign in to comment.