In Github/MD, if we want to enable code 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
To highlight code, write the name of the language the code is written in after the initial triple backticks. In the above example, the code is written in JavaScript, and hence javascript is added after triple backticks.
To link to multiple lines of highlighted code, select your first line of code and then CTRL+SHIFT click on the last line of code you want to highlight. Notice the URL is now appended with a range of line numbers (e.g. https://github.com/…/functions.php#L117-L148).
You can also create a Markdown hyperlink by highlighting the text and using the keyboard shortcut Command + V .
By default, markdown does not support text highlight content. There are multiple ways we can do it using HTML.
```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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With