haderlka19 downloadsAdd line numbers, a file name and highlighted lines to code blocks without changing how they are highlighted or run.
Line numbers, a file name and highlighted lines for your code blocks. You write the options in the first line of an ordinary fenced code block. Syntax highlighting, the copy button and plugins that run code keep working as before.
Source code: github.com/haderlka/obsidian-code-block-numbers. Issues and ideas are welcome.
If this plugin is useful to you, you can support its development:

Put the options after the language in the first line of the code block:
```python title="utils/math.py" start=10 hl=10,13-14
def mean(values):
"""Average of a list.
Returns 0 for an empty list."""
if not values:
return 0
return sum(values) / len(values)
```
| Option | What it does | Example |
|---|---|---|
title=… |
File name shown above the code. Use quotes if it contains spaces. | title="my file.py" |
start=N |
Number of the first line. Optional, the default is 1. | start=10 |
hl=… |
Lines to highlight: single lines and ranges, separated by commas. They refer to the displayed numbers, so with start=10, hl=10 highlights the first line. Optional. |
hl=2,5-7 |
ln / ln=false |
Turns line numbers on or off for this block, overriding the setting. | ln=false |
All options are optional, can be combined and can appear in any order. The language always comes first, because Obsidian and other plugins read the first word as the language.
Also understood:
file= and filename= for title=highlight= for hl=: instead of =, for example title:"x" or hl:2-4ln:10 means "numbers on, starting at 10"Number all code blocks (on by default). When this is off, only blocks with ln or start=… get numbers. Titles and highlights always work.
{…} arguments can stay in the same line: ```python {label="demo"} title=run.py.From Obsidian: Settings → Community plugins → Browse, search for "Code Block Numbers", install and enable it.
Manually: download main.js, manifest.json and styles.css from the latest release into <vault>/.obsidian/plugins/code-block-numbers/, then enable the plugin under Settings → Community plugins.