Compare commits

..

2 Commits

Author SHA1 Message Date
jolheiser 590777dea0
feat: custom lexer registry
Signed-off-by: jolheiser <git@jolheiser.com>
2024-07-31 22:18:17 -05:00
jolheiser df7ace7fae
feat: ugit-uci
Signed-off-by: jolheiser <git@jolheiser.com>
2024-07-31 22:09:52 -05:00
2 changed files with 24 additions and 8 deletions

View File

@ -11,7 +11,7 @@ import (
"github.com/go-git/go-git/v5"
)
func main() {
func maine() error {
repoDir, ok := os.LookupEnv("UGIT_REPODIR")
if !ok {
panic("UGIT_REPODIR not set")
@ -31,30 +31,38 @@ func main() {
repo, err := git.PlainOpen(repoDir)
if err != nil {
panic(err)
return fmt.Errorf("could not open git dir %q: %w", repoDir, err)
}
tree, err := repo.Worktree()
if err != nil {
panic(err)
return fmt.Errorf("could not get worktree: %w", err)
}
fi, err := tree.Filesystem.Open(*manifestFlag)
if err != nil {
panic(err)
return fmt.Errorf("could not open manifest %q: %w", *manifestFlag, err)
}
defer fi.Close()
data, err := io.ReadAll(fi)
if err != nil {
panic(err)
return fmt.Errorf("could not read manifest: %w", err)
}
resp, err := http.Post(*urlFlag, "applicaiton/jsonnet", bytes.NewReader(data))
resp, err := http.Post(*urlFlag, "application/jsonnet", bytes.NewReader(data))
if err != nil {
panic(err)
return fmt.Errorf("could not post manifest: %w", err)
}
if resp.StatusCode != http.StatusOK {
panic(fmt.Sprintf("non-ok response: %s", resp.Status))
return fmt.Errorf("non-ok response: %s", resp.Status)
}
return nil
}
func main() {
if err := maine(); err != nil {
fmt.Println(err)
}
}

View File

@ -2,6 +2,7 @@ package markup
import (
"io"
"path/filepath"
"github.com/alecthomas/chroma/v2"
"github.com/alecthomas/chroma/v2/formatters/html"
@ -26,10 +27,17 @@ var (
type code struct{}
var customReg = map[string]string{
".hujson": "json",
}
func setup(source []byte, fileName string) (chroma.Iterator, *chroma.Style, error) {
lexer := lexers.Match(fileName)
if lexer == nil {
lexer = lexers.Fallback
if name, ok := customReg[filepath.Ext(fileName)]; ok {
lexer = lexers.Get(name)
}
}
lexer = chroma.Coalesce(lexer)