如何将两个Markdown代码块并排显示

30

我想要将一个源代码的两个块并排展示——重构前和重构后。是否可以创建两个并排的代码块?如果不行,那么有什么替代方案吗?


你的输出格式是什么? - scoa
6
可能是 Markdown 中的两列代码 的重复问题。 - Waylan
理想情况下,我的输出格式应该是HTML。 - Lukasz Dynowski
2个回答

16

使用原始Markdown语法无法在单个表格单元格中创建多行代码块,但您可以使用原样的HTML来实现。这是一个示例双列表格,其中包含并排显示的代码(请注意,此HTML与您的Markdown一起并排显示):

# Document Title

The usual [Markdown Cheatsheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet)
does not cover some of the more advanced Markdown tricks, but here
is one. You can combine verbatim HTML with your Markdown. 
This is particularly useful for tables.
Notice that with **empty separating lines** we can use Markdown inside HTML:

<table>
<tr>
<th>Json 1</th>
<th>Markdown</th>
</tr>
<tr>
<td>
<pre>
{
  "id": 1,
  "username": "joe",
  "email": "joe@example.com",
  "order_id": "3544fc0"
}
</pre>
</td>
<td>

```json
{
  "id": 5,
  "username": "mary",
  "email": "mary@example.com",
  "order_id": "f7177da"
}
```

</td>
</tr>
</table>

这将呈现为:

在Markdown中的双栏表格


2
但是这样代码就无法自动进行语法高亮了.. 真遗憾。 - vsync

6
另一篇答案的修改版本可以在Github上获得并排显示的语法高亮:
# Document Title

The usual [Markdown Cheatsheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet)
does not cover some of the more advanced Markdown tricks, but here
is one. You can combine verbatim HTML with your Markdown. 
This is particularly useful for tables.
Notice that with **empty separating lines** we can use Markdown inside HTML:

<table>
<tr>
<th>Json 1</th>
<th>Markdown</th>
</tr>
<tr>
<td>
  
```json
{
  "id": 1,
  "username": "joe",
  "email": "joe@example.com",
  "order_id": "3544fc0"
}
```
  
</td>
<td>

```json
{
  "id": 5,
  "username": "mary",
  "email": "mary@example.com",
  "order_id": "f7177da"
}
```

</td>
</tr>
</table>

示例:https://gist.github.com/nottheswimmer/7837eec10fac0d1197fc5a8bfc0b96f3


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接