Code blocks Material
Code blocks Material
Section titled “Code blocks Material”Syntax
Section titled “Syntax”| Form | Syntax | Usage |
|---|---|---|
| Langage | fence js | Coloration syntaxique. |
| Title | fence py title="app.py" | File name. |
| Title only | fence title=".browserslistrc" | File name without syntax highlighting. |
| Numbers | linenums="1" | Numerotation. |
| Surlignage | hl_lines="2 4-6" | Highlighted source lines. |
| Attributes | fence { .yaml linenums="1" } | Syntax Material. |
| Copie | fence { .yaml .no-copy } | Copy button hidden. |
| Shell | fence bash-root | Root prompt. |
| One line | fence yaml value | Compact block. |
| Annotation | # (1) then 1. Explanation | Code bubble. |
One-line code
Section titled “One-line code”``` yaml site_name: Demo ```
``` yaml
site_name: Demo
```
site_name: Demo
site_name: Demo
~~~ py title="bubble_sort.py"
def bubble_sort(items):
return items
~~~
def bubble_sort(items):
return items
Title without language
Section titled “Title without language”~~~ title=".browserslistrc"
last 4 years
~~~
last 4 years
Line numbers and highlighting
Section titled “Line numbers and highlighting”~~~ py linenums="1" hl_lines="2 3"
def bubble_sort(items):
for i in range(len(items)):
print(i)
return items
~~~
def bubble_sort(items):
for i in range(len(items)):
print(i)
return items
Attributes in braces
Section titled “Attributes in braces”~~~ { .yaml .copy title="config.yml" linenums="3" hl_lines="4" }
site_name: Demo
theme:
name: material
~~~
site_name: Demo
theme:
name: material
No copy
Section titled “No copy”~~~ { .bash .no-copy title="install.sh" }
npm install
npm run build
~~~
npm install
npm run build
Bash root
Section titled “Bash root”~~~bash-root
apt update
apt install nginx
systemctl restart nginx
~~~
apt update
apt install nginx
systemctl restart nginx
File tabs
Section titled “File tabs”=== "app.py"
~~~ py title="app.py" linenums="1" hl_lines="4"
from fastapi import FastAPI
app = FastAPI()
app.title = "Demo"
~~~
=== "config.yml"
~~~ yaml title="config.yml" linenums="1"
site_name: Demo
theme:
name: material
~~~
=== "package.json"
~~~ { .json .no-copy title="package.json" }
{
"scripts": {
"dev": "astro dev"
}
}
~~~
from fastapi import FastAPI
app = FastAPI()
app.title = "Demo"
site_name: Demo
theme:
name: material
{
"scripts": {
"dev": "astro dev"
}
}
Annotations
Section titled “Annotations”~~~ yaml title="mkdocs.yml"
theme:
name: material # (1)
features:
- content.code.copy # (2)
~~~
theme:
name: material # (1)
features:
- content.code.copy # (2)