forked from thecodingmachine/gotenberg-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarkdown.go
48 lines (41 loc) · 1.13 KB
/
markdown.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
package gotenberg
// MarkdownRequest facilitates Markdown conversion
// with the Gotenberg API.
type MarkdownRequest struct {
index Document
markdowns []Document
assets []Document
*chromeRequest
}
// NewMarkdownRequest create MarkdownRequest.
func NewMarkdownRequest(index Document, markdowns ...Document) *MarkdownRequest {
return &MarkdownRequest{index, markdowns, []Document{}, newChromeRequest()}
}
// Assets sets assets form files.
func (req *MarkdownRequest) Assets(assets ...Document) {
req.assets = assets
}
func (req *MarkdownRequest) postURL() string {
return "/convert/markdown"
}
func (req *MarkdownRequest) formFiles() map[string]Document {
files := make(map[string]Document)
files["index.html"] = req.index
for _, markdown := range req.markdowns {
files[markdown.Filename()] = markdown
}
if req.header != nil {
files["header.html"] = req.header
}
if req.footer != nil {
files["footer.html"] = req.footer
}
for _, asset := range req.assets {
files[asset.Filename()] = asset
}
return files
}
// Compile-time checks to ensure type implements desired interfaces.
var (
_ = Request(new(MarkdownRequest))
)