Skip to content

Instantly share code, notes, and snippets.

@hayajo
Created September 10, 2015 03:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hayajo/e635f85372ebcd2b2542 to your computer and use it in GitHub Desktop.
Save hayajo/e635f85372ebcd2b2542 to your computer and use it in GitHub Desktop.
MarkdownからHTMLを生成する
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"text/template"
"github.com/russross/blackfriday"
)
var tmpl = `
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>{{.title}}</title>
</head>
<body>
{{.body}}
</body>
</html>
`
func main() {
var title string
flag.StringVar(&title, "title", "md2html", "page title")
flag.Parse()
markdown, _ := ioutil.ReadAll(os.Stdin)
html := string(blackfriday.MarkdownCommon(markdown))
t, err := template.New("").Parse(tmpl)
if err != nil {
fmt.Fprint(os.Stderr, err)
os.Exit(1)
}
t.Execute(os.Stdout, map[string]string{"title": title, "body": html})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment