MCPcopy Create free account
hub / github.com/diillson/chatcli / topLevelFenceOpener

Function topLevelFenceOpener

cli/cli_rendering.go:164–180  ·  view source on GitHub ↗

topLevelFenceOpener reports whether a line opens a fenced code block at column 0, returning the fence token ("```" or "~~~") and the declared language (the info string's first word, lowercased).

(line string)

Source from the content-addressed store, hash-verified

162// column 0, returning the fence token ("```" or "~~~") and the declared
163// language (the info string's first word, lowercased).
164func topLevelFenceOpener(line string) (fence, lang string, ok bool) {
165 switch {
166 case strings.HasPrefix(line, "```"):
167 fence = "```"
168 case strings.HasPrefix(line, "~~~"):
169 fence = "~~~"
170 default:
171 return "", "", false
172 }
173 info := strings.TrimSpace(strings.TrimPrefix(line, fence))
174 // A line that is only the fence with trailing back-ticks is not an opener
175 // with a language; info may be empty (plain code block).
176 if idx := strings.IndexAny(info, " \t"); idx >= 0 {
177 info = info[:idx]
178 }
179 return fence, strings.ToLower(info), true
180}
181
182// isFenceCloser reports whether a line closes a fence opened with the given
183// token. A closer is the fence token at column 0 with only optional trailing

Callers 1

splitTopLevelCodeBlocksFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected