Markdown中表格行内的代码块

问题描述 投票:29回答:2

我在Github风味的Markdown中整理了一些文档,我想把一个有两行的表放在一起。一个只有文本,一个带有json代码块。这是一个例子。

| Status | Response  |
|---|---|
| 200 |  |
| 400 |   |

我想在响应行中获取此代码,但是当我尝试完全中断时。

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"
}

我是Markdown的新手,如果有人能指出我正确的方向,我将非常感激。

markdown github-flavored-markdown
2个回答
16
投票

github markdown doc声明您可以在表格单元格中包含内联/跨度降价标记。除了少数试图建立对表格布局的更多控制之外,对于大多数降价标记都是如此。

您可以使用内联代码元素,但不会使用语法着色或行缩进格式化。

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

或者,使用html以老式方式创建表格,这样可以为rowspan提供更好的布局控制。


8
投票

Github flavored Markdown supports HTML tags

简单地说吧(尽管StackOverflow不支持) -

<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>

输出:

github markdown table-code


您也可以尝试这样的基于文本的表(适用于StackOverflow) -

+---------------+--------+---------+
|       \       | Rating | Comment |
+---------------+--------+---------+
| One Piece     |  A | B |       ♢ |
+---------------+----+---+---------+
| Naruto        |  A | C |       ♧ |
+---------------+----+---+---------+
| One Punch Man |  A | A |       ♥ |
+---------------+----+---+---------+
| Death Note    |  A | B |       ♠ |
+---------------+----+---+---------+

Text Tables Generator是一个很棒的网站。

© www.soinside.com 2019 - 2024. All rights reserved.