Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 
like image 988
Howard Avatar asked Jun 04 '11 09:06

Howard


People also ask

How do you highlight code blocks in Markdown?

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.

How do I highlight a block of code on GitHub?

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).

How do I highlight a Markdown in GitHub?

You can also create a Markdown hyperlink by highlighting the text and using the keyboard shortcut Command + V .

Does Markdown support highlighting?

By default, markdown does not support text highlight content. There are multiple ways we can do it using HTML.


1 Answers

```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:

indented code block

like image 122
VonC Avatar answered Oct 13 '22 17:10

VonC