Irina Rapoport
Irina Rapoport

Reputation: 334

Why is Github API rendering my markdown incorrectly?

I am doing this:

curl -X POST -d @a.md  https://api.github.com/markdown/raw --header "Content-Type:text/x-markdown" > a.html

a.md

# Hello, world!
### This is markdown!
How are you doing?

a.html

<h1>
<a id="user-content-hello-world-this-is-markdownhow-are-you-doing" class="anchor" href="#hello-world-this-is-markdownhow-are-you-doing" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Hello, world!### This is markdown!How are you doing?</h1>

Rendered a.html

Hello, world!### This is markdown!How are you doing?

I even tried adding Windows-style cr/lf, did not help:

CR=$(printf '\r')
sed "s/\$/$CR/" a.md > b.md

What am I doing wrong?

The docs for Github API for Markdown are here.

Upvotes: 0

Views: 1273

Answers (2)

PePa
PePa

Reputation: 69

Use --data-binary instead of --data and then you don't have to use JSON. So from your example:

curl -X POST --data-binary @a.md  https://api.github.com/markdown/raw --header "Content-Type:text/x-markdown" > a.html

Upvotes: 1

krc
krc

Reputation: 513

Couple things...

First, your a.md file needs to look like this:

{
    "text" : "# Hello, world!\n
    ### This is markdown!\n
    How are you doing?",
    "mode" : "markdown",
    "context" : "none"
}

Second, you are calling markdown raw, which won't help, the following CURL request worked for me:

curl --data @a.md https://api.github.com/markdown > a.html

The output for me from that command with that file is:

<h1>
<a id="user-content-hello-world" class="anchor" href="#hello-world" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Hello, world!</h1>

<h3>
<a id="user-content-this-is-markdown" class="anchor" href="#this-is-markdown" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>This is markdown!</h3>

<p>How are you doing?</p>

Hope this helps!

Upvotes: 1

Related Questions