【问题标题】:How to disply two markdown code blocks side by side如何并排显示两个markdown代码块
【发布时间】:2022-04-23 06:10:12
【问题描述】:

我想并排显示两个源代码块 - 重构之前和之后。是否可以并排创建两个代码块?如果不是,那么替代解决方案是什么?

【问题讨论】:

标签: markdown


【解决方案1】:

无法使用纯 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>

呈现为:

【讨论】:

  • 但是代码将不会自动语法高亮.. 可惜
【解决方案2】:

另一个答案的修改版本确实可以在 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-06-25
    • 2018-05-21
    • 1970-01-01
    • 1970-01-01
    • 2021-09-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多