-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
45 lines (40 loc) · 900 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
45
// This is Free Software covered by the terms of the MIT license.
// See LICENSE file for details.
// Copyright 2017 by Intevation GmbH
package main
import (
"flag"
"io"
"io/ioutil"
"log"
"os"
"strings"
)
func check(err error) {
if err != nil {
log.Fatalf("error: %v\n", err)
}
}
func main() {
format := flag.String(
"format", "xhtml", `Format to export to ("xhtml" or "latex").`)
standalone := flag.Bool(
"standalone", false, `Generate a complete standalone document.`)
flag.Parse()
var export func(*document, io.Writer, bool) error
switch strings.ToLower(*format) {
case "xhtml":
export = exportXHTML
case "latex":
export = exportLaTex
default:
log.Fatalln("Unknown export format.")
}
data, err := ioutil.ReadAll(os.Stdin)
check(err)
input := string(data)
b := newBuilder()
doc, err := b.parse(input)
check(err)
check(export(doc, os.Stdout, *standalone))
}