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

Function injectChipSentinels

cli/cli_rendering.go:64–79  ·  view source on GitHub ↗

injectChipSentinels rewrites the source so each top-level fenced code block with a declared language is preceded by a sentinel paragraph. Returns the rewritten source and whether any sentinel was added. Reconstructing the document from the segments is loss-less: splitTopLevelCodeBlocks partitions th

(input string)

Source from the content-addressed store, hash-verified

62// the lines contiguously, so joining the parts with "\n" reproduces the
63// original text (plus the inserted sentinels).
64func injectChipSentinels(input string) (string, bool) {
65 segs := splitTopLevelCodeBlocks(input)
66 has := false
67 parts := make([]string, 0, len(segs))
68 for _, s := range segs {
69 if s.isCode && s.lang != "" {
70 // Blank line + sentinel line, so glamour treats the sentinel as a
71 // standalone paragraph immediately above the code block.
72 parts = append(parts, "\n"+chipSentinelOpen+s.lang+chipSentinelClose+"\n"+s.text)
73 has = true
74 } else {
75 parts = append(parts, s.text)
76 }
77 }
78 return strings.Join(parts, "\n"), has
79}
80
81// replaceChipSentinels swaps each rendered sentinel line for the themed
82// language chip. It matches on the raw line (the marker survives as one

Callers 1

renderMarkdownMethod · 0.85

Calls 1

splitTopLevelCodeBlocksFunction · 0.85

Tested by

no test coverage detected