File: markdown.go

package info (click to toggle)
golang-gitlab-gitlab-org-api-client-go 0.123.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,356 kB
  • sloc: makefile: 17
file content (47 lines) | stat: -rw-r--r-- 1,375 bytes parent folder | download | duplicates (4)
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
package gitlab

import "net/http"

// MarkdownService handles communication with the markdown related methods of
// the GitLab API.
//
// Gitlab API docs: https://docs.gitlab.com/ee/api/markdown.html
type MarkdownService struct {
	client *Client
}

// Markdown represents a markdown document.
//
// Gitlab API docs: https://docs.gitlab.com/ee/api/markdown.html
type Markdown struct {
	HTML string `json:"html"`
}

// RenderOptions represents the available Render() options.
//
// Gitlab API docs:
// https://docs.gitlab.com/ee/api/markdown.html#render-an-arbitrary-markdown-document
type RenderOptions struct {
	Text                    *string `url:"text,omitempty" json:"text,omitempty"`
	GitlabFlavouredMarkdown *bool   `url:"gfm,omitempty" json:"gfm,omitempty"`
	Project                 *string `url:"project,omitempty" json:"project,omitempty"`
}

// Render an arbitrary markdown document.
//
// Gitlab API docs:
// https://docs.gitlab.com/ee/api/markdown.html#render-an-arbitrary-markdown-document
func (s *MarkdownService) Render(opt *RenderOptions, options ...RequestOptionFunc) (*Markdown, *Response, error) {
	req, err := s.client.NewRequest(http.MethodPost, "markdown", opt, options)
	if err != nil {
		return nil, nil, err
	}

	md := new(Markdown)
	response, err := s.client.Do(req, md)
	if err != nil {
		return nil, response, err
	}

	return md, response, nil
}