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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use octocrate_core::*;
#[allow(unused_imports)]
use octocrate_types::*;
#[allow(unused_imports)]
use serde::{Deserialize, Serialize};
#[allow(unused_imports)]
use typed_builder::TypedBuilder;
pub mod render {
#[allow(unused_imports)]
use super::*;
#[allow(clippy::large_enum_variant)]
/// The rendering mode.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Copy)]
pub enum RequestMode {
#[serde(rename = "markdown")]
Markdown,
#[serde(rename = "gfm")]
Gfm,
}
impl std::fmt::Display for RequestMode {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
RequestMode::Markdown => write!(f, "markdown"),
RequestMode::Gfm => write!(f, "gfm"),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, TypedBuilder)]
#[builder(field_defaults(setter(into)))]
pub struct Request {
/// The repository context to use when creating references in `gfm` mode. For example, setting `context` to `octo-org/octo-repo` will change the text `#42` into an HTML link to issue 42 in the `octo-org/octo-repo` repository.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
pub context: Option<String>,
/// The rendering mode.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
pub mode: Option<RequestMode>,
/// The Markdown text to render in HTML.
pub text: String,
}
}
/// Render GitHub flavored markdown
pub struct GitHubMarkdownAPI {
config: SharedAPIConfig,
}
impl GitHubMarkdownAPI {
pub fn new(config: &SharedAPIConfig) -> Self {
Self {
config: config.clone(),
}
}
/// **Render a Markdown document**
///
///
/// *Documentation*: [https://docs.github.com/rest/markdown/markdown#render-a-markdown-document](https://docs.github.com/rest/markdown/markdown#render-a-markdown-document)
pub fn render(&self) -> NoContentRequest<render::Request, ()> {
let url = format!("/markdown");
NoContentRequest::<render::Request, ()>::builder(&self.config)
.post(url)
.build()
}
/// **Render a Markdown document in raw mode**
///
/// You must send Markdown as plain text (using a `Content-Type` header of `text/plain` or `text/x-markdown`) to this endpoint, rather than using JSON format. In raw mode, [GitHub Flavored Markdown](https://github.github.com/gfm/) is not supported and Markdown will be rendered in plain format like a README.md file. Markdown content must be 400 KB or less.
///
/// *Documentation*: [https://docs.github.com/rest/markdown/markdown#render-a-markdown-document-in-raw-mode](https://docs.github.com/rest/markdown/markdown#render-a-markdown-document-in-raw-mode)
pub fn render_raw(&self) -> NoContentRequest<(), ()> {
let url = format!("/markdown/raw");
NoContentRequest::<(), ()>::builder(&self.config)
.post(url)
.build()
}
}