-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhighlight.go
More file actions
62 lines (48 loc) · 1.24 KB
/
highlight.go
File metadata and controls
62 lines (48 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
// chroma is being used for syntax highlighting
import (
"io"
"os"
"github.com/alecthomas/chroma/v2"
"github.com/alecthomas/chroma/v2/formatters"
"github.com/alecthomas/chroma/v2/lexers"
"github.com/alecthomas/chroma/v2/styles"
)
func selectMDStyle(style string) (*chroma.Style, error) {
// style, ok := styles.Registry[cli.Style]
// if ok {
// return style, nil
// }
r, err := os.Open(style)
if err != nil {
return nil, err
}
defer r.Close()
return chroma.NewXMLStyle(r)
}
func Highlight(w io.Writer, source, lexer, formatter, style string) error {
l := lexers.Get(lexer)
// Commenting this out did not fix multiline comments enclosed by
/* ... */
l = chroma.Coalesce(l)
f := formatters.Get(formatter)
s := styles.Get(style)
it, err := l.Tokenise(nil, source)
if err != nil {
return err
}
return f.Format(w, s, it)
}
func Highlight2(w io.Writer, source string, lexer string, formatter string, style *chroma.Style) error {
l := lexers.Get(lexer)
// Commenting this out did not fix multiline comments enclosed by
/* ... */
l = chroma.Coalesce(l)
f := formatters.Get(formatter)
//s := styles.Get(style)
it, err := l.Tokenise(nil, source)
if err != nil {
return err
}
return f.Format(w, style, it)
}