Codeblock
By default, LFP Docs supports syntax highlighting inside of Markdown code fences, when a valid language name is given:
```python
<your code...>
```
Codeblocks present a wrapper around these Markdown code segments, including a copy button for quickly copying the code to clipboard, and an optional file name or path.
Definition
| Argument | Type | Notes |
|---|---|---|
| content | string |
The string content passed between opening and closing tags |
| filename | string|undefined |
An optional filename, displayed alongside the listing |
Usage
Codeblock expects a string parseable for Markdown, Liquid, Nunjucks; the author has to include Markdown code fences, if they want to use LFPDocs syntax highlighting.
{% codeblock "fibonacci.py" %}
```python
def fibonacci(n):
if n <= 0:
return 0
elif n == 1:
return 1
fib = [0] * (n + 1)
fib[1] = 1
for i in range(2, n + 1):
fib[i] = fib[i - 1] + fib[i - 2]
return fib[n]
```
{% endcodeblock %}
The above code yields the following rendered codeblock with filename and copy button:
def fibonacci(n):
if n <= 0:
return 0
elif n == 1:
return 1
fib = [0] * (n + 1)
fib[1] = 1
for i in range(2, n + 1):
fib[i] = fib[i - 1] + fib[i - 2]
return fib[n]