Skip to content

Commit 40c3af3

Browse files
author
Vicent Marti
committed
Document the Markdown API
1 parent 2001311 commit 40c3af3

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

content/v3/markdown.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: Markdown Rendering | GitHub API
3+
---
4+
5+
# Markdown Rendering API
6+
7+
## Render an arbritrary Markdown document
8+
9+
POST /markdown
10+
11+
### Input
12+
13+
text
14+
: _Required_ **string** - The Markdown text to render
15+
16+
mode
17+
: _Optional_ **string** - The rendering mode
18+
19+
- `markdown` to render a document as plain Markdown, just like README files are rendered.
20+
- `gfm` to render a document as user-content, e.g. like user comments or issues are rendered. In GFM mode, hard line breaks are always taken into account, and issue and user mentions are linked accordingly.
21+
22+
context
23+
: _Optional_ **string** - The repository context, only taken into account when rendering as `gfm`
24+
25+
<%= json \
26+
:text => "Hello world github/linguist#1 **cool**, and #1!",
27+
:mode => "gfm",
28+
:context => "github/gollum"
29+
%>
30+
31+
### Response
32+
33+
<%= text_html \
34+
%(<p>Hello world <a href="http://github.com/github/linguist/issues/1" class="issue-link" title="This is a simple issue">github/linguist#1</a> <strong>cool</strong>, and <a href="http://github.com/github/gollum/issues/1" class="issue-link" title="This is another issue">#1</a>!</p>), 200
35+
%>
36+
37+
# Render a Markdown document in raw mode
38+
39+
POST /markdown/raw
40+
41+
### Input
42+
43+
The raw API it not JSON-based. It takes a Markdown document as plaintext (`text/plain` or `text/x-markdown`) and renders it as plain Markdown without a repository context (just like a README.md file is rendered -- this is the simplest way to preview a readme online).
44+
45+
### Response
46+
47+
<%= text_html \
48+
%(<p>Hello world github/linguist#1 <strong>cool</strong>, and #1!</p>), 200
49+
%>

layouts/default.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ <h3><a href="#" class="js-expand-btn collapsed">&nbsp;</a><a href="/v3/search/">
120120
<li><a href="/v3/search/#email-search">Email</a></li>
121121
</ul>
122122
</li>
123+
<li class="js-guides"><h3><a href="/v3/markdown/">Markdown</a></h3></li>
123124
</ul>
124125
</div> <!-- /sidebar-module -->
125126
<div class="sidebar-module">

lib/resources.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'pp'
22
require 'yajl/json_gem'
33
require 'stringio'
4+
require 'cgi'
45

56
module GitHub
67
module Resources
@@ -54,6 +55,12 @@ def json(key)
5455
%(<pre class="highlight"><code class="language-javascript">) +
5556
JSON.pretty_generate(hash) + "</code></pre>"
5657
end
58+
59+
def text_html(response, status, head = {})
60+
hs = headers(status, head.merge('Content-Type' => 'text/html'))
61+
res = CGI.escapeHTML(response)
62+
hs + %(<pre class="highlight"><code>) + res + "</code></pre>"
63+
end
5764
end
5865

5966
USER = {

0 commit comments

Comments
 (0)