MCPcopy Create free account
hub / github.com/github/gh-aw / extractCodeBlockMarker

Function extractCodeBlockMarker

pkg/workflow/xml_comments.go:128–164  ·  view source on GitHub ↗

extractCodeBlockMarker extracts the marker string and language from a code block line Returns marker string (e.g., "```", "~~~~") and language specifier

(trimmedLine string)

Source from the content-addressed store, hash-verified

126// extractCodeBlockMarker extracts the marker string and language from a code block line
127// Returns marker string (e.g., "```", "~~~~") and language specifier
128func extractCodeBlockMarker(trimmedLine string) (string, string) {
129 if len(trimmedLine) < 3 {
130 return "", ""
131 }
132
133 var count int
134
135 // Check for backticks
136 if strings.HasPrefix(trimmedLine, "```") {
137 for i, r := range trimmedLine {
138 if r == '`' {
139 count++
140 } else {
141 // Found language specifier or other content
142 return strings.Repeat("`", count), strings.TrimSpace(trimmedLine[i:])
143 }
144 }
145 // All characters are backticks
146 return strings.Repeat("`", count), ""
147 }
148
149 // Check for tildes
150 if strings.HasPrefix(trimmedLine, "~~~") {
151 for i, r := range trimmedLine {
152 if r == '~' {
153 count++
154 } else {
155 // Found language specifier or other content
156 return strings.Repeat("~", count), strings.TrimSpace(trimmedLine[i:])
157 }
158 }
159 // All characters are tildes
160 return strings.Repeat("~", count), ""
161 }
162
163 return "", ""
164}
165
166// isValidCodeBlockMarker checks if a trimmed line is a valid code block marker (3 or more ` or ~)
167func isValidCodeBlockMarker(trimmedLine string) bool {

Callers 4

removeXMLCommentsFunction · 0.85
isValidCodeBlockMarkerFunction · 0.85

Calls

no outgoing calls

Tested by 1