gitea/src/8f1a0130-e555-4e6a-9fa8-9b9.../code.power

61 lines
1.4 KiB
Plaintext

/**
* Render a markdown document as HTML.
*
* @param string $markdownText The markdown text to render.
* @param bool $isWikiPage Is it a wiki page?
* @param string $context Context to render.
* @param string $mode Mode to render.
*
* @return string|null
* @since 3.2.0
**/
public function render(
string $markdownText,
bool $isWikiPage = false,
string $context = 'string',
string $mode = 'string'
): ?string
{
// Build the request path.
$path = "/markdown";
// Set the markdown data.
$data = new \stdClass();
$data->Text = $markdownText;
$data->Wiki = $isWikiPage;
$data->Context = $context;
$data->Mode = $mode;
// Send the post request.
return $this->response->get(
$this->http->post(
$this->uri->get($path),
json_encode($data),
['accept' => 'text/html']
)
);
}
/**
* Render raw markdown as HTML.
*
* @param string $rawMarkdown The raw markdown text to render.
*
* @return string|null
* @since 3.2.0
**/
public function raw(string $rawMarkdown): ?string
{
// Build the request path.
$path = "/markdown/raw";
// Send the post request.
return $this->response->get(
$this->http->post(
$this->uri->get($path),
$rawMarkdown,
['Content-Type' => 'text/plain', 'accept' => 'text/html']
)
);
}