Markdown/Github: syntax highlighting of code block as a child of a list
In Github/MD, if we want to enable 开发者_如何学Ccode block when it is a child of list, we need to intent it by 8 spaces.
But how to make that code block has the syntax highlighting feature?
The following code does not work as expected...
1. foo
```python
print 'bar'
```
2. bar
```python
print 'bar'
```
without spaces should work: from GitHub help page:
Just wrap your code blocks in ``` and you won't need to indent manually to trigger a code block.
As illustrated in hilz's answer below, you need to indent the ```` with the same indentation level + 2 spaces than your list.
The content of the code block doesn't need to be indented.
1. foo
````python
print 'bar'
````
1.
````python
print 'bar'
````
See this gist as an example:
To get code blocks with syntax highlighting embedded happily in a list, embed the markup lines that come before and after the code block to the appropriate level of indenting for an additional paragraph, then proceed as normal. For example:
1. lorem ipsum
```ruby
resources :dolor
```
1. sit amet
```ruby
resources :elit
```
1. sed do
1. eiusmod
indents each code block to the appropriate depth and maintains the integrity of the indexes.
Nowadays, you have to do the following:
1. lorem ipsum
```perl
use strict;
```
2. dolor sit amet
```perl
use warnings;
```
1. consectetur adipiscing elit
1. sed do
1. eiusmod
That is, make sure your syntax-highlighted code starts in the same column as the backticks. You also have to help the numbering out a little bit, because it appears to lose count after code blocks.
See also: https://gist.github.com/therealbstern/9cb0dfc7f0f4b76a062247676aed341b
精彩评论