Created
September 10, 2015 03:39
-
-
Save hayajo/e635f85372ebcd2b2542 to your computer and use it in GitHub Desktop.
MarkdownからHTMLを生成する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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