MCPcopy Create free account
hub / github.com/alibaba/open-code-review / extractCodeBlock

Function extractCodeBlock

internal/diff/relocation.go:82–100  ·  view source on GitHub ↗

extractCodeBlock extracts the content of the first fenced code block from text. Returns empty string if no code block is found.

(text string)

Source from the content-addressed store, hash-verified

80// extractCodeBlock extracts the content of the first fenced code block from text.
81// Returns empty string if no code block is found.
82func extractCodeBlock(text string) string {
83 text = strings.TrimSpace(text)
84 start := strings.Index(text, "```")
85 if start < 0 {
86 return ""
87 }
88 afterOpen := start + 3
89 // Skip optional language tag on the opening fence line.
90 if nl := strings.IndexByte(text[afterOpen:], '\n'); nl >= 0 {
91 afterOpen += nl + 1
92 } else {
93 return ""
94 }
95 end := strings.Index(text[afterOpen:], "```")
96 if end < 0 {
97 return ""
98 }
99 return strings.TrimSpace(text[afterOpen : afterOpen+end])
100}

Callers 2

ReLocateCommentFunction · 0.85
TestExtractCodeBlockFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestExtractCodeBlockFunction · 0.68