forked from thecodingmachine/gotenberg-go-client
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmarkdown.go
58 lines (47 loc) · 1.48 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
49
50
51
52
53
54
55
56
57
58
package gotenberg
import "github.com/starwalkn/gotenberg-go-client/v8/document"
const (
endpointMarkdownConvert = "/forms/chromium/convert/markdown"
endpointMarkdownScreenshot = "/forms/chromium/screenshot/markdown"
)
// MarkdownRequest facilitates Markdown conversion with the Gotenberg API.
type MarkdownRequest struct {
index document.Document
markdowns []document.Document
assets []document.Document
*chromiumRequest
}
func NewMarkdownRequest(index document.Document, markdowns ...document.Document) *MarkdownRequest {
return &MarkdownRequest{index, markdowns, []document.Document{}, newChromiumRequest()}
}
func (req *MarkdownRequest) endpoint() string {
return endpointMarkdownConvert
}
func (req *MarkdownRequest) screenshotEndpoint() string {
return endpointMarkdownScreenshot
}
func (req *MarkdownRequest) formDocuments() map[string]document.Document {
files := make(map[string]document.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
}
// Assets sets assets form files.
func (req *MarkdownRequest) Assets(assets ...document.Document) {
req.assets = assets
}
// Compile-time checks to ensure type implements desired interfaces.
var (
_ = multipartRequester(new(MarkdownRequest))
)