Skip to main content
 首页 » 编程设计

github之Markdown /Github : syntax highlighting of code block as a child of a list

2024年11月01日37thcjp

在 Github/MD 中,如果我们想在它是列表的子项时启用代码块,我们需要将其意图 8 个空格。

但是如何使该代码块具有语法高亮功能呢?

以下代码无法按预期工作...

    1. foo 
 
             ```python 
                print 'bar' 
             ``` 
 
    2. bar 

请您参考如下方法:

```python 
print 'bar' 
``` 

没有空格应该可以工作:来自 GitHub help page :

Just wrap your code blocks in ``` and you won't need to indent manually to trigger a code block.



hilz 中所示的 answer在下面,您需要使用与列表相同的缩进级别 + 2 个空格来缩进 ````。
代码块内容无需缩进 .
1. foo 
 
  ````python 
print 'bar' 
  ```` 
 
  1. 
 
    ````python 
print 'bar' 
    ```` 

this gist as an example :