2018-01-29 00:16:11 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
|
2020-02-10 16:46:14 +00:00
|
|
|
"github.com/status-im/markdown"
|
|
|
|
"github.com/status-im/markdown/ast"
|
|
|
|
"github.com/status-im/markdown/parser"
|
2018-01-29 00:16:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
2019-02-02 11:26:55 +00:00
|
|
|
exts := parser.CommonExtensions // parser.OrderedListStart | parser.NoEmptyLineBeforeBlock
|
|
|
|
p := parser.NewWithExtensions(exts)
|
|
|
|
doc := markdown.Parse(d, p)
|
2018-01-29 00:16:11 +00:00
|
|
|
fmt.Printf("Ast of file '%s':\n", fileName)
|
2019-02-02 03:14:26 +00:00
|
|
|
ast.PrintWithPrefix(os.Stdout, doc, " ")
|
2018-01-29 00:16:11 +00:00
|
|
|
fmt.Print("\n")
|
|
|
|
}
|
|
|
|
}
|