CLI
The lanexio-parser CLI parses HTML and Markdown files, runs LexQuery patterns, and serializes parse trees back to source. The binary is installed under two names: lanexio-parser (canonical) and parser (short alias). This page uses the canonical name throughout.
Package: @lanexio/parser-cli
Runtime: Node.js only.
Install
Section titled “Install”pnpm add -g @lanexio/parser-cliSubcommands
Section titled “Subcommands”| Subcommand | Description |
|---|---|
lanexio-parser parse <file> | Parse a file and print the tree or JSON. |
lanexio-parser query <selector> <file> | Run a LexQuery pattern and print matching nodes. |
lanexio-parser serialize <file> | Parse and re-serialize to source markup. |
Every subcommand also accepts --help/-h and prints its own usage screen (exit code 0).
lanexio-parser parse index.htmllanexio-parser parse README.mdlanexio-parser parse --grammar html --output json - < input.htmlOptions
Section titled “Options”| Flag | Values | Default | Description |
|---|---|---|---|
--grammar | html, markdown, auto | auto | Grammar to use. auto infers from file extension. |
--output | tree, json | tree | Output format. tree prints an indented text representation; json prints the full serialized tree. |
Grammar auto-detection
Section titled “Grammar auto-detection”| Extension | Grammar |
|---|---|
.html, .htm, .xhtml, .svg | html |
.md, .markdown, .mdx | markdown |
When reading from stdin (-), --grammar is required.
Exit codes
Section titled “Exit codes”| Code | Meaning |
|---|---|
0 | Success. A tree was produced, even if it contains LexError nodes. Also: any --help invocation. |
1 | Invocation or I/O error: file not found, unknown subcommand, unknown flag, invalid flag value, unrecognized grammar, invalid selector, or stdin with no --grammar. |
The CLI always exits 0 when a tree was produced, even when the input has parse errors — check the JSON output’s per-node hasError to detect malformed input. Invocation mistakes, by contrast, always fail loudly:
lanexio-parser pares file.html # unknown subcommand → stderr + exit 1lanexio-parser parse --ouput json a.html # unknown flag → stderr + exit 1lanexio-parser parse --output yaml a.html # invalid value → "must be tree or json" + exit 1Unknown subcommands, unknown flags, and invalid flag values are all rejected with a message on stderr and exit code 1 — they are never silently ignored.
lanexio-parser query Element index.htmllanexio-parser query "Element, Text" --grammar html --output json - < input.htmlOptions
Section titled “Options”| Flag | Values | Default | Description |
|---|---|---|---|
--grammar | html, markdown, auto | auto | Grammar to use. |
--output | text, json | text | Output format. |
serialize
Section titled “serialize”lanexio-parser serialize index.htmllanexio-parser serialize --grammar html - < input.htmlParses the input and prints the serialized output to stdout. Both HTML and Markdown serialization are supported. The grammar is detected from the file extension or specified with --grammar.
lanexio-parser serialize --grammar markdown README.mdserialize writes its output byte-exact — no trailing newline is appended — so round-trip comparisons like lanexio-parser serialize a.html | diff - a.html behave predictably. The parse and query dumps end with a single trailing newline.
Reading from stdin
Section titled “Reading from stdin”Use - as the file argument (the file argument is always required — piping without - is an error):
echo '<p>Hello</p>' | lanexio-parser parse --grammar html -cat index.html | lanexio-parser parse --grammar html --output json -When reading from stdin, --grammar is required, and the check happens before any bytes are read — lanexio-parser parse - without --grammar fails immediately instead of blocking on stdin until end-of-input.
Known limitations in v1.0
Section titled “Known limitations in v1.0”- Query selectors are kind names, not CSS selectors.
query h1finds nodes of kindh1(which does not exist), not<h1>elements. - No
--include-errorsflag. Theparse --output jsonformat includeshasErrorper node. - One input file per invocation. Extra positional arguments are rejected.