(code, filePath string)
| 194 | } |
| 195 | |
| 196 | func 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 | |
| 221 | func parseAndRenderSegs(sourcePath string) ([]*Seg, string) { |
| 222 | segs, filecontent := parseSegs(sourcePath) |
no test coverage detected