Skip to content

Instantly share code, notes, and snippets.

@gnilchee
Created September 25, 2017 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnilchee/344c281a86f8c9f73da72192ecc57bfc to your computer and use it in GitHub Desktop.
Save gnilchee/344c281a86f8c9f73da72192ecc57bfc to your computer and use it in GitHub Desktop.
Take multiline code in a variable and output to stdout html that has code in syntax highlighted in given format
package main
import (
"fmt"
"os"
"github.com/alecthomas/chroma/quick"
)
func main() {
my_code := `package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}`
err := quick.Highlight(os.Stdout, my_code, "go", "html", "monokai")
if err != nil {
fmt.Println("There was an issue")
os.Exit(1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment