-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (35 loc) · 896 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
package main
import (
"fmt"
"io/ioutil"
"os"
"github.com/markbates/markdownr"
"github.com/markbates/markdownr/ast"
"github.com/markbates/markdownr/parser"
)
// This prints AST of parsed markdown document.
// Usage: printast <markdown-file>
func usageAndExit() {
fmt.Printf("Usage: printast <markdown-file>\n")
os.Exit(1)
}
func main() {
nFiles := len(os.Args) - 1
if nFiles < 1 {
usageAndExit()
}
for i := 0; i < nFiles; i++ {
fileName := os.Args[i+1]
d, err := ioutil.ReadFile(fileName)
if err != nil {
fmt.Fprintf(os.Stderr, "Couldn't open '%s', error: '%s'\n", fileName, err)
continue
}
exts := parser.CommonExtensions // parser.OrderedListStart | parser.NoEmptyLineBeforeBlock
p := parser.NewWithExtensions(exts)
doc := markdown.Parse(d, p)
fmt.Printf("Ast of file '%s':\n", fileName)
ast.PrintWithPrefix(os.Stdout, doc, " ")
fmt.Print("\n")
}
}