MCPcopy Index your code
hub / github.com/docker/docker-agent / highlightYAML

Function highlightYAML

cmd/root/agent_picker.go:465–482  ·  view source on GitHub ↗

highlightYAML syntax-colorizes YAML using chroma with the active TUI theme. On any tokenisation error it returns the (sanitized) source unchanged.

(src string)

Source from the content-addressed store, hash-verified

463// highlightYAML syntax-colorizes YAML using chroma with the active TUI theme.
464// On any tokenisation error it returns the (sanitized) source unchanged.
465func highlightYAML(src string) string {
466 src = sanitizeYAML(src)
467 lexer := lexers.Get("yaml")
468 if lexer == nil {
469 return src
470 }
471 iterator, err := chroma.Coalesce(lexer).Tokenise(nil, src)
472 if err != nil {
473 return src
474 }
475
476 style := styles.ChromaStyle()
477 var b strings.Builder
478 for _, token := range iterator.Tokens() {
479 b.WriteString(chromaTokenStyle(token.Type, style).Render(token.Value))
480 }
481 return b.String()
482}
483
484// sanitizeYAML normalizes line endings, expands tabs, and strips terminal
485// control characters from config content that may come from untrusted (remote)

Callers 3

detailsContentMethod · 0.85
TestHighlightYAMLFunction · 0.85

Calls 6

ChromaStyleFunction · 0.92
sanitizeYAMLFunction · 0.85
chromaTokenStyleFunction · 0.85
GetMethod · 0.65
RenderMethod · 0.65
StringMethod · 0.45

Tested by 2

TestHighlightYAMLFunction · 0.68