Display code in Markdown documents.
Inline Code
Use backticks for inline code:
Use the `parse()` function.
Escape backticks with more backticks:
`` `code` with backticks ``
Fenced Code Blocks
Use triple backticks:
```python
def hello():
print("Hello, World!")
```
Or triple tildes:
~~~python
def hello():
print("Hello, World!")
~~~
Language Hints
Specify language for syntax highlighting:
```python
import patitas
```
```javascript
console.log("Hello");
```
```bash
pip install patitas
```
Indented Code Blocks
Indent with 4 spaces:
def hello():
print("Hello")
Code in Lists
Indent code blocks in lists:
1. First step:
```python
parse("# Hello")
- Second step
## Syntax Highlighting
Install the `syntax` extra for highlighting:
```bash
pip install patitas[syntax]
Then use the Rosettes highlighter:
from patitas import Markdown
from patitas.highlighting import set_highlighter
from rosettes import highlight
set_highlighter(highlight)
md = Markdown()
html = md("```python\nprint('hello')\n```")