// Package gfmutil offers functionality to render GitHub Flavored Markdown to io.Writer. package gfmutil import ( "bytes" "io" "net/http" "github.com/shurcooL/github_flavored_markdown" ) // TODO: Change API to return errors rather than panicking. // WriteGitHubFlavoredMarkdownViaLocal converts GitHub Flavored Markdown to full HTML page and writes it to w. // It assumes that GFM CSS is available at /assets/gfm/gfm.css. func WriteGitHubFlavoredMarkdownViaLocal(w io.Writer, markdown []byte) { io.WriteString(w, `
`) w.Write(github_flavored_markdown.Markdown(markdown)) io.WriteString(w, `
`) } // WriteGitHubFlavoredMarkdownViaGitHub converts GitHub Flavored Markdown to full HTML page and writes it to w // by using GitHub API. // It assumes that GFM CSS is available at /assets/gfm/gfm.css. func WriteGitHubFlavoredMarkdownViaGitHub(w io.Writer, markdown []byte) { io.WriteString(w, `
`) // Convert GitHub Flavored Markdown to HTML (includes syntax highlighting for diff, Go, etc.) resp, err := http.Post("https://api.github.com/markdown/raw", "text/x-markdown", bytes.NewReader(markdown)) if err != nil { panic(err) } defer resp.Body.Close() _, err = io.Copy(w, resp.Body) if err != nil { panic(err) } io.WriteString(w, `
`) }