pygments-beancount#
pygments-beancount is a Pygments lexer for Beancount ledgers.
Install it, and ```beancount code blocks highlight in every tool that highlights code with Pygments.
There is nothing to configure: Pygments finds the lexer through its plugin entry point.
pip install pygments-beancount
Add it to the dependency group that builds your documentation:
uv add --group docs pygments-beancount
1option "operating_currency" "USD"
2
32026-01-01 open Assets:Bank:Checking USD
42026-01-01 open Assets:Brokerage ACME, USD
5 institution: "Example Bank"
62026-01-01 open Income:Salary USD
7
8; Salary arrives on the fifth.
92026-01-05 * "Employer" "Salary for January" #payroll ^payslip-2026-01
10 Assets:Bank:Checking 4,250.00 USD
11 Income:Salary -4,250.00 USD
12
132026-01-12 * "Buy shares"
14 Assets:Brokerage 10 ACME {50.25 USD}
15 Assets:Bank:Checking -502.50 USD
16
172026-01-31 price ACME 51.10 USD
182026-01-31 balance Assets:Bank:Checking 3,747.50 USD
Every Beancount block on these pages is highlighted by the lexer this documentation describes. The token reference shows the token each element becomes.
Names it answers to#
Use |
Value |
|---|---|
Code block language |
|
File names |
|
MIME type |
|
Where it works#
Any tool that looks lexers up through Pygments:
Sphinx and MyST, with no change to
conf.py; see Use the lexer in Sphinx and MyST.MkDocs, Material for MkDocs, Pelican and other Python-Markdown sites; see Highlight ledgers in MkDocs and Python-Markdown.
pygmentizeand Python code; see Highlight ledgers outside Sphinx.
Hugo, Zola and browser-side highlighters such as highlight.js do not use Pygments, so the package has no effect there.
Where to go next#
New to the package? Build a small Sphinx site with a highlighted ledger in five minutes.
Use the lexer in Sphinx, MyST, MkDocs, Pelican, pygmentize and Python.
The token each Beancount element becomes, and the lexer’s API.
How the lexer follows Beancount’s scanner, and why it never reports an error.