markdown/cmd/main.go

54 lines
1.0 KiB
Go
Raw Normal View History

2010-11-21 22:04:39 +00:00
package main
import (
2010-12-01 18:40:56 +00:00
"../_obj/github.com/knieriem/markdown"
2010-11-21 22:04:39 +00:00
"flag"
"fmt"
"os"
"bufio"
"io/ioutil"
"log"
"runtime/pprof"
2010-11-21 22:04:39 +00:00
)
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
2010-11-21 22:04:39 +00:00
func main() {
var b []byte
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [FILE]\n", os.Args[0])
flag.PrintDefaults()
}
optNotes := flag.Bool("notes", false, "turn on footnote syntax")
optSmart := flag.Bool("smart", false, "turn on smart quotes, dashes, and ellipses")
2010-12-01 18:40:56 +00:00
optDlists := flag.Bool("dlists", false, "support definitions lists")
2010-11-21 22:04:39 +00:00
flag.Parse()
if flag.NArg() > 0 {
b, _ = ioutil.ReadFile(flag.Arg(0))
} else {
b, _ = ioutil.ReadAll(os.Stdin)
}
2010-12-01 18:40:56 +00:00
e := markdown.Extensions{
Notes: *optNotes,
Smart: *optSmart,
2010-12-01 18:40:56 +00:00
Dlists: *optDlists,
2010-11-21 22:04:39 +00:00
}
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
2010-12-01 18:40:56 +00:00
doc := markdown.Parse(string(b), e)
2010-11-21 22:04:39 +00:00
w := bufio.NewWriter(os.Stdout)
doc.WriteHtml(w)
w.Flush()
}