diff --git a/internal/lib/pandoc.go b/internal/lib/pandoc.go index df47e14..42701b0 100644 --- a/internal/lib/pandoc.go +++ b/internal/lib/pandoc.go @@ -2,6 +2,7 @@ package lib import ( "bytes" + "context" "encoding/json" "io" "net/http" @@ -25,7 +26,7 @@ type convertRequest struct { To string `json:"to"` } -func (client *PandocClient) convert(text, from, to string) (string, error) { +func (client *PandocClient) convert(ctx context.Context, text, from, to string) (string, error) { body, err := json.Marshal(convertRequest{ Text: text, From: from, @@ -37,7 +38,12 @@ func (client *PandocClient) convert(text, from, to string) (string, error) { buf := bytes.NewBuffer(body) - resp, err := client.client.Post(client.address, "application/json", buf) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, client.address, buf) + if err != nil { + return "", err + } + req.Header.Set("Content-Type", "application/json") + resp, err := client.client.Do(req) if err != nil { return "", err } @@ -56,6 +62,6 @@ func (client *PandocClient) convert(text, from, to string) (string, error) { return string(body), nil } -func (client *PandocClient) ConvertLatexToHtml5(text string) (string, error) { - return client.convert(text, "latex", "html5") +func (client *PandocClient) ConvertLatexToHtml5(ctx context.Context, text string) (string, error) { + return client.convert(ctx, text, "latex", "html5") }