Search code examples
markdowngithub-flavored-markdown

code block inside table row in Markdown


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.


Solution

  • The github markdown doc states that you can include inline/span markdown tags within table cells. This is the same for most flavours of markdown other than a few which have been trying to establish more control over table layouts.

    You could get close with inline code elements, but that will not format with syntax colouring, or line indents.

    | Status | Response  |
    | ------ | --------- |
    | 200    | `json`                          |
    |        | `   {`                          |
    |        | ` "id": 10,`                    |
    |        | ` "username": "alanpartridge",` |
    |        | ` more code...`                 |
    |        | `}`                             |
    | 400    |                                 |
    

    Alternatively, create your table the old-fashioned way with html, which gives you rowspan for greater layout control.