I am putting together some documentation in Github flavoured Markdown and I want to put together a table that has two rows. One with simply text and one with a json code block. Heres an example.
| Status | Response | |---|---| | 200 | | | 400 | |
I want to get this code inside the response row but when ever I try it completely breaks.
json { "id": 10, "username": "alanpartridge", "email": "[email protected]", "password_hash": "$2a$10$uhUIUmVWVnrBWx9rrDWhS.CPCWCZsyqqa8./whhfzBZydX7yvahHS", "password_salt": "$2a$10$uhUIUmVWVnrBWx9rrDWhS.", "created_at": "2015-02-14T20:45:26.433Z", "updated_at": "2015-02-14T20:45:26.540Z" }
I am new to Markdown and if anyone could point me in the right direction it would be very much appreciated.
The basic Markdown syntax allows you to create code blocks by indenting lines by four spaces or one tab. If you find that inconvenient, try using fenced code blocks. Depending on your Markdown processor or editor, you'll use three backticks ( ``` ) or three tildes ( ~~~ ) on the lines before and after the code block.
Embedding Code in Markdown. If you're writing your code in markdown, the easiest way to embed snippets is to use "fenced code blocks", which also allows syntax highlighting. For examples in practice, see this assemble boilerplate for markdown projects, in particular take a look at the code in these templates.
To highlight code, write the name of the language the code is written in after the initial triple backticks. In the above example, the code is written in JavaScript, and hence javascript is added after triple backticks. You can find this example gist here.
We can create checkboxes in markdown using a dash, a space, and a square bracket. Keep in mind that this is an extended feature and will depend on the Markdown application.
As others have pointed out, you'll have to use HTML <table>
tags to create the table. It is possible however to format the contents of the table cells using Markdown only
Markdown syntax within HTML blocks works if you leave extra blank lines around the HTML tags: one after the <td>
and one before the </td>
otherwise the Markdown inside won't be parsed! This creates a new <p>
paragraph where Markdown parsing is re-enabled inside the table cells.
<table> <tr> <td> Status </td> <td> Response </td> </tr> <tr> <td> 200 </td> <td> ^ Extra blank line above! ```json json { "id": 10, "username": "alanpartridge", "email": "[email protected]", "password_hash": "$2a$10$uhUIUmVWVnrBWx9rrDWhS.CPCWCZsyqqa8./whhfzBZydX7yvahHS", "password_salt": "$2a$10$uhUIUmVWVnrBWx9rrDWhS.", "created_at": "2015-02-14T20:45:26.433Z", "updated_at": "2015-02-14T20:45:26.540Z" } ``` V Extra blank line below! </td> </tr> <tr> <td> 400 </td> <td> **Markdown** _here_. (Blank lines needed before and after!) </td> </tr> </table>
(If you want to fix the bad vertical alignment between "400" and "Markdown here", add blank lines around the "400" too, which will wrap that in a <p>
as well.)
<table> <tr> <th> Status </th> <th> Response </th> </tr> <tr> <td> <pre> <br/><br/><br/>200<br/><br/><br/><br/><br/>400<br/> </pre> </td> <td> <pre> json { "id": 10, "username": "alanpartridge", "email": "[email protected]", "password_hash": "$2a$10$uhUIUmVWVnrBWx9rrDWhS.CPCWCZsyqqa8./whhfzBZydX7yvahHS", "password_salt": "$2a$10$uhUIUmVWVnrBWx9rrDWhS.", "created_at": "2015-02-14T20:45:26.433Z", "updated_at": "2015-02-14T20:45:26.540Z" } </pre> </td> </tr> </table>
Markdown Editor can really be helpful to visualize output as you write.
Instead of <pre>
tag we may also use triple-backticks ```
for showing a code block.
EDIT: You may also try text-based table like this-
+---------------+--------+---------+ | \ | Rating | Comment | +---------------+--------+---------+ | One Piece | A | B | ♢ | +---------------+----+---+---------+ | Naruto | A | C | ♧ | +---------------+----+---+---------+ | One Punch Man | A | A | ♥ | +---------------+----+---+---------+ | Death Note | A | B | ♠ | +---------------+----+---+---------+
Text Tables Generator is a wonderful site for this purpose.
EDIT 2: The following code works both for GitHub and StackOverflow-
| Name | Signature Code | |------|--------------------------------| | Minhas Kamal | <pre>main(m,k){<br> for(<br> ;<br> m%k--?:(k=m++);<br> k^1?:printf("%i\|",m)<br> );<br>}</pre> |
Output-
Name | Signature Code |
---|---|
Minhas Kamal | main(m,k){ |
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With