MCPcopy
hub / github.com/gobyexample-cn/gobyexample / chromaFormat

Function chromaFormat

tools/generate.go:196–219  ·  view source on GitHub ↗
(code, filePath string)

Source from the content-addressed store, hash-verified

194}
195
196func chromaFormat(code, filePath string) string {
197 lexer := lexers.Get(filePath)
198 if lexer == nil {
199 lexer = lexers.Fallback
200 }
201
202 if strings.HasSuffix(filePath, ".sh") {
203 lexer = SimpleShellOutputLexer
204 }
205
206 lexer = chroma.Coalesce(lexer)
207
208 style := styles.Get("swapoff")
209 if style == nil {
210 style = styles.Fallback
211 }
212 formatter := html.New(html.WithClasses(true))
213 iterator, err := lexer.Tokenise(nil, string(code))
214 check(err)
215 buf := new(bytes.Buffer)
216 err = formatter.Format(buf, style, iterator)
217 check(err)
218 return buf.String()
219}
220
221func parseAndRenderSegs(sourcePath string) ([]*Seg, string) {
222 segs, filecontent := parseSegs(sourcePath)

Callers 1

parseAndRenderSegsFunction · 0.85

Calls 2

StringMethod · 0.80
checkFunction · 0.70

Tested by

no test coverage detected