-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (40 loc) · 765 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
46
47
48
49
50
51
package main
import (
"bytes"
"encoding/json"
"fmt"
"os"
"github.com/slack-go/slack"
"github.com/yuin/goldmark"
"github.com/vslinko/mdblockkit/renderer"
)
type Result struct {
Blocks slack.Blocks `json:"blocks"`
}
func main() {
if len(os.Args) < 2 {
fmt.Println("Usage: mdblockkit MD_FILE")
os.Exit(1)
}
data, err := os.ReadFile(os.Args[1])
if err != nil {
panic(err)
}
result := Result{}
markdown := goldmark.New(
goldmark.WithRenderer(
renderer.CreateMyRenderer(&result.Blocks),
),
)
var buf bytes.Buffer
err = markdown.Convert(data, &buf)
if err != nil {
panic(err)
}
jsonData, err := json.MarshalIndent(result, "", " ")
if err != nil {
panic(err)
}
os.Stdout.Write(jsonData)
os.Stdout.Write([]byte("\n"))
}