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

Function extractCodeBlock

internal/diff/relocation.go:99–117  ·  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

97// extractCodeBlock extracts the content of the first fenced code block from text.
98// Returns empty string if no code block is found.
99func extractCodeBlock(text string) string {
100 text = strings.TrimSpace(text)
101 start := strings.Index(text, "```")
102 if start < 0 {
103 return ""
104 }
105 afterOpen := start + 3
106 // Skip optional language tag on the opening fence line.
107 if nl := strings.IndexByte(text[afterOpen:], '\n'); nl >= 0 {
108 afterOpen += nl + 1
109 } else {
110 return ""
111 }
112 end := strings.Index(text[afterOpen:], "```")
113 if end < 0 {
114 return ""
115 }
116 return strings.TrimSpace(text[afterOpen : afterOpen+end])
117}

Callers 2

ReLocateCommentFunction · 0.85
TestExtractCodeBlockFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestExtractCodeBlockFunction · 0.68