Skip to main content
REST API 现已经过版本控制。 有关详细信息,请参阅“关于 API 版本控制”。

Markdown 的 REST API 终结点

使用 REST API 渲染 markdown 文档作为 HTML 页面或原始文本。

Render a Markdown document

“Render a Markdown document”的细粒度访问令牌

此端点支持以下精细令牌类型:

精细令牌不需要任何权限。

如果仅请求公共资源,则无需身份验证即可使用此终结点。

“Render a Markdown document”的参数

标头
名称, 类型, 说明
accept string

Setting to application/vnd.github+json is recommended.

正文参数
名称, 类型, 说明
text string 必须

The Markdown text to render in HTML.

mode string

The rendering mode.

默认: markdown

可以是以下选项之一: markdown, gfm

context string

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.

“Render a Markdown document”的 HTTP 响应状态代码

状态代码说明
200

OK

304

Not modified

“Render a Markdown document”的示例代码

If you access GitHub at GHE.com, replace api.github.com with your enterprise's dedicated subdomain at api.SUBDOMAIN.ghe.com.

请求示例

post/markdown
curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/markdown \ -d '{"text":"Hello **world**"}'

Example response

Status: 200
"<p>Hello <strong>world</strong></p>"

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 is not supported and Markdown will be rendered in plain format like a README.md file. Markdown content must be 400 KB or less.

“Render a Markdown document in raw mode”的细粒度访问令牌

此端点支持以下精细令牌类型:

精细令牌不需要任何权限。

如果仅请求公共资源,则无需身份验证即可使用此终结点。

“Render a Markdown document in raw mode”的 HTTP 响应状态代码

状态代码说明
200

OK

304

Not modified

“Render a Markdown document in raw mode”的示例代码

If you access GitHub at GHE.com, replace api.github.com with your enterprise's dedicated subdomain at api.SUBDOMAIN.ghe.com.

请求示例

post/markdown/raw
curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/markdown/raw \ -d '{"text":"Hello **world**"}'

Example response

Status: 200
"<p>Hello <strong>world</strong></p>"