-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransform.go
More file actions
55 lines (42 loc) · 1.29 KB
/
transform.go
File metadata and controls
55 lines (42 loc) · 1.29 KB
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
package mwgo
import (
"encoding/json"
"github.com/Lakelimbo/mwgo/misc"
)
type TransformRequest struct {
client *Client
}
type TransformBody struct {
Wikitext string `json:"wikitext,omitempty"`
HTML string `json:"html,omitempty"`
}
// WikitextToHTML converts wikitext to HTML.
func (r *TransformRequest) WikitextToHTML(title string, body TransformBody) (string, error) {
r.client.Method = "POST"
b, err := json.Marshal(body)
if err != nil {
return "", err
}
r.client.Body = b
return r.client.requestRawString(misc.PATH_TRANSFORM + "/wikitext/to/html/" + title)
}
// HTMLToWikitext converts HTML to wikitext.
func (r *TransformRequest) HTMLToWikitext(title string, body TransformBody) (string, error) {
r.client.Method = "POST"
b, err := json.Marshal(body)
if err != nil {
return "", err
}
r.client.Body = b
return r.client.requestRawString(misc.PATH_TRANSFORM + "/html/to/wikitext/" + title)
}
// LintErrors transforms wikitext into a JSON array of lint errors, if any.
func (r *TransformRequest) LintErrors(title string, body TransformBody) (*[]map[string]any, error) {
r.client.Method = "POST"
b, err := json.Marshal(body)
if err != nil {
return nil, err
}
r.client.Body = b
return exec[[]map[string]any](r.client, misc.PATH_TRANSFORM+"/wikitext/to/lint/", title, nil)
}