@giduru/codemirror-lang-hledger
v0.5.0
Published
hledger journal format language support for CodeMirror
Maintainers
Readme
@giduru/codemirror-lang-hledger
hledger journal format language support for CodeMirror 6.
Features
- Syntax highlighting for transactions, postings, amounts, account names, dates, comments, directives, and more
- Code folding for transactions and multi-line directives
- Auto-indentation for postings under transaction headers
- Autocompletion for directive keywords and common account prefixes
- Toggle line comments with
;
Installation
npm install @giduru/codemirror-lang-hledgerUsage
import {EditorView, basicSetup} from "codemirror"
import {hledger} from "@giduru/codemirror-lang-hledger"
new EditorView({
extensions: [basicSetup, hledger()],
parent: document.body
})If you only need the language without autocompletion and folding:
import {hledgerLanguage} from "@giduru/codemirror-lang-hledger"Supported syntax
- Transactions: dates (including
DATE=DATE2), status markers (*/!), codes, payee|description text, same-line;comments, indented transaction comments - Postings: account names (with single-space support and journal-style semicolons), amounts, commodity symbols, cost (
@/@@), balance assertions (=/==/=*/==*), lot prices ({...}/{{...}}), lot dates ([DATE]), inline comments - Virtual postings:
(account)and[account]syntax - Periodic transactions:
~ monthly,~ weekly, etc. - Auto posting rules:
= query - Directives:
account,commodity,payee,tag,include,alias,end aliases,decimal-mark,apply account,apply year,apply tag,apply fixed,end ...,assert,capture,check,define,expr,value,eval,P(market price),D(default commodity),Y/year,C,A/bucket,N, and command-line--flagdirectives - Directive details: same-line
;comments on account/commodity/include/payee/tag directives, commodityformatsubdirectives, and legacy!/@directive prefixes - Price directives:
Pdirectives expose structuredPriceDate,PriceCommodity, andPriceAmountnodes instead of flattening the body into one generic argument string - Comments: line comments (
;,#,*), indented top-level file comments, and block comments (comment...end comment) - Date formats:
YYYY-MM-DD,YYYY/MM/DD,YYYY.MM.DD
Notes
- The grammar models journal syntax, not all of hledger's semantic validation rules.
- Transaction codes are still part of
TxnDescription, not a separate AST node. - Tags and posting dates embedded inside comment text are still extracted by a higher-level parser layer, not by the Lezer grammar itself.
- Multi-line
pythondirectives are not modeled yet.
