Update pkg/utils/message.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
0a9d24e2a2
commit
4ccee85561
1 changed files with 6 additions and 5 deletions
|
|
@ -74,21 +74,22 @@ func SplitMessage(content string, maxLen int) []string {
|
||||||
// FindLastUnclosedCodeBlock finds the last opening ``` that doesn't have a closing ```
|
// FindLastUnclosedCodeBlock finds the last opening ``` that doesn't have a closing ```
|
||||||
// Returns the position of the opening ``` or -1 if all code blocks are complete
|
// Returns the position of the opening ``` or -1 if all code blocks are complete
|
||||||
func FindLastUnclosedCodeBlock(text string) int {
|
func FindLastUnclosedCodeBlock(text string) int {
|
||||||
count := 0
|
inCodeBlock := false
|
||||||
lastOpenIdx := -1
|
lastOpenIdx := -1
|
||||||
|
|
||||||
for i := 0; i < len(text); i++ {
|
for i := 0; i < len(text); i++ {
|
||||||
if i+2 < len(text) && text[i] == '`' && text[i+1] == '`' && text[i+2] == '`' {
|
if i+2 < len(text) && text[i] == '`' && text[i+1] == '`' && text[i+2] == '`' {
|
||||||
if count == 0 {
|
// Toggle code block state on each fence
|
||||||
|
if !inCodeBlock {
|
||||||
|
// Entering a code block: record this opening fence
|
||||||
lastOpenIdx = i
|
lastOpenIdx = i
|
||||||
}
|
}
|
||||||
count++
|
inCodeBlock = !inCodeBlock
|
||||||
i += 2
|
i += 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If odd number of ``` markers, last one is unclosed
|
if inCodeBlock {
|
||||||
if count%2 == 1 {
|
|
||||||
return lastOpenIdx
|
return lastOpenIdx
|
||||||
}
|
}
|
||||||
return -1
|
return -1
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue