-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
44 lines (36 loc) · 903 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"flag"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
"github.com/arnabsen1729/md2pdf/parser"
"github.com/arnabsen1729/md2pdf/writer"
)
// readFile to read the contents of the file and return string.
func readFile(fileName string) string {
content, err := ioutil.ReadFile(fileName)
if err != nil {
log.Fatal(err)
os.Exit(1)
}
return string(content)
}
func main() {
fileName := flag.String("file", "", "Name of the markdown file to be converted")
outputFileName := flag.String("output", "", "Name of the generated PDF file (default: <input-file-name>.pdf)")
flag.Parse()
if *fileName == "" {
flag.Usage()
os.Exit(1)
}
if *outputFileName == "" {
*outputFileName = strings.TrimSuffix(*fileName, filepath.Ext(*fileName))
}
md := readFile(*fileName)
par := parser.NewParser(md)
pdf := writer.NewWriter(par.Lines)
pdf.Export(*outputFileName)
}