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

```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.
Long Code Block
Give a code block a filename - Meta Stack Overflow
Making a github like code block in html
element. For the text highlighting, you'll need JavaScript for that. Look up highlight.js More on reddit.com syntax-highlighting code-blocks in Markdown: question about tree-sitter
How do I add syntax highlighting to a Markdown code block?
python or javascript. The renderer applies syntax highlighting based on the language identifier. GitHub, VS Code, and GitLab all support this.Which programming languages are supported in Markdown code blocks?
How do you write inline code in Markdown?
). For example, code` renders as inline code. Use this for short snippets, variable names, or commands within a sentence.I fully agree with the proposal and I don't understand all of the downvotes.
This is already doable e.g. via python markdown extensions, like this:
``` py title="bubble_sort.py"
def bubble_sort(items):
for i in range(len(items)):
for j in range(len(items) - 1 - i):
if items[j] > items[j + 1]:
items[j], items[j + 1] = items[j + 1], items[j]
```
See here:
- https://squidfunk.github.io/mkdocs-material/setup/extensions/python-markdown-extensions/#snippets
- https://squidfunk.github.io/mkdocs-material/reference/code-blocks/#adding-a-title
It's relevant and useful to include the name of the file that a code block should go in
Not always. Many questions give a short block of text as an example of where they're having the problem, and answers respond with an amended version of the code block. It doesn't matter what the name of the file is (it really could be anything with an appropriate extension). The code might not even be for a file! Most regexes, for example, can be used in almost any language, but where I find myself using them most often is in the search box of my IDE. Furthermore, not everything that finds itself in a code block is even code (e.g. error messages).
Needless to say, you don't need to provide a file name (or even a context) for every block of code. So we're back to the start: People will still assume they don't need to include the file name when it would be helpful to do so. Or maybe people will include a file name in contexts where they don't need to, making the post noisier.
Lastly, I prefer regular markdown formatting (if not plain text) over your suggestion, both aesthetically and formatting-wise — your suggested format is much too tricky for the vast majority of people to use.