Пример #1
0
func AsTerm(src []byte, isDark bool) ([]byte, error) {
	var buf bytes.Buffer
	config := LightTermConfig
	if isDark {
		config = DarkTermConfig
	}
	err := syntaxhighlight.Print(syntaxhighlight.NewScanner(src), &buf,
		TermPrinter(config))
	// err := highlight_go.Print(src, &buf, TermPrinter(config))
	if err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}
Пример #2
0
// TODO: Support highlighting for more languages.
func highlightCode(src []byte, lang string) (highlightedCode []byte, ok bool) {
	switch lang {
	case "go":
		var buf bytes.Buffer
		err := highlight_go.Print(src, &buf, syntaxhighlight.HTMLPrinter(gfmHTMLConfig))
		if err != nil {
			return nil, false
		}
		return buf.Bytes(), true
	case "go-old":
		var buf bytes.Buffer
		err := syntaxhighlight.Print(syntaxhighlight.NewScanner(src), &buf, syntaxhighlight.HTMLPrinter(gfmHTMLConfig))
		if err != nil {
			return nil, false
		}
		return buf.Bytes(), true

	default:
		return nil, false
	}
}