CLI Tool
The gridwell CLI converts table IR files to any supported format, validates them, and formats, inspects and draws them for debugging.
Installation
The CLI isn’t on crates.io yet; install it from the repository (this needs Rust 1.85 or later):
cargo install --locked --git https://github.com/rich-iannone/gridwell gridwell-cliCommands
gridwell convert
Convert a table IR JSON file to an output format. The input is validated first; if it is invalid, the validation errors are printed to stderr, nothing is written, and the exit code is 1. If the table uses a feature the format can’t express, a warning saying where is printed to stderr after the output is written, as is one for a table of a newer minor IR version and one for each thing of the table this gridwell leaves out; none changes the exit code.
gridwell convert [OPTIONS] --to <FORMAT> [INPUT]
gridwell convert [OPTIONS] -o <FILE> [INPUT]Arguments:
[INPUT]— Input file path (use-or omit for stdin)
Options:
-t, --to <FORMAT>— Output format (seegridwell formats); required unless-ois given, when it is inferred from the file extension-o, --output <FILE>— Output file (defaults to stdout for text; required for binary). The extension picks the format:.html,.tex,.typ,.rtf,.svg,.txt(ansi),.docx,.xlsx,.pptx..jsonis both pandoc and quarto, so it needs--to;--toalways wins over the extension. A.txt(ansi) file is plain text unless the options set"color": true-O, --options <JSON>— Writer options as a JSON object--options-file <FILE>— Read writer options from a JSON file
Examples:
# Render to HTML (stdout)
gridwell convert table.json --to html
# Render to file (format from the extension)
gridwell convert table.json -o table.tex
# Binary format requires -o
gridwell convert table.json -o report.docx
# .json needs --to
gridwell convert table.json --to quarto -o quarto.json
# Writer options
gridwell convert table.json --to html --options '{"inline_styles": true}'
# From stdin
cat table.json | gridwell convert --to html
# Pipe through other tools
gridwell convert table.json --to html | pbcopygridwell validate
Check an IR file for structural errors. Exits with code 0 if valid, code 1 if errors found. A valid table is also checked for features the output formats can’t express, and each one is listed as a warning; warnings don’t change the exit code.
gridwell validate [OPTIONS] [INPUT]Options:
-t, --to <FORMAT>— Warn only of what this format can’t express (default: every format)
Example output
$ gridwell validate hello.json
Valid: no errors found.
$ gridwell validate --to typst borders.json
Valid: no errors found.
1 warning(s):
- [UNSUPPORTED_FEATURE] typst can't express border-double (head row 1, column 1 and 2 other places): Typst strokes have no double line; a double border is drawn solid
$ gridwell validate broken_table.json
Found 2 validation error(s):
- [COL_COUNT] tbody group 0 row 0 has 4 cells but config.table_cols is 3
- [SPAN_OVERFLOW_RIGHT] Cell at tbody group 1 (row=0, col=2) has colspan=2 but table only has 3 columns (would need col index up to 3)gridwell fmt
Print an IR file in canonical form: every object’s keys sorted, two-space indents, LF line endings and a final newline. Once two IR files are formatted, a text diff of them shows only what differs in their JSON, not key order or whitespace.
The input must parse as IR, but it needn’t be valid, so an invalid file can be formatted before it’s fixed. It is formatted as JSON: every field is kept, including ones gridwell doesn’t know, and nothing is added. Numbers are written as gridwell reads them, so 1e3 becomes 1000.0, and an integer too big for 64 bits becomes a float.
gridwell fmt [OPTIONS] [INPUT]Options:
--check— Print nothing if the input is in canonical form; if it isn’t, say so on stderr and exit with code 1
# Canonical form, to stdout
gridwell fmt table.json
# From stdin
cat table.json | gridwell fmtExample output
$ gridwell fmt --check hello.json
hello.json is not in canonical form (see `gridwell fmt`)gridwell inspect
Print what an IR file holds: its columns, rows, groups, spans, styles, notes and content nodes, counted. The styles that nothing uses are listed (a definition is used when a composition that’s used extends it). An invalid table is inspected too; its count of validation errors is one of the lines, and gridwell validate lists them.
gridwell inspect [OPTIONS] [INPUT]Options:
--json— Print the counts as JSON, with every style used and unused listed
Example output
$ gridwell inspect spanners.json
IR version: 1.0
Valid: yes
Columns: 3
Header: none
Head rows: 2
Body: 2 rows in 1 group
Summary rows: 0
Spans: 2 spanning cells, 2 placeholders
Styles: 0 definitions, 0 compositions, 0 conditionals; 0 used
Unused styles: none
Footnotes: 0
Source notes: 0
Content: 10 text
Typed values: none
Extensions: nonegridwell grid
Draw the occupancy grid of each section (the head, each group’s rows and each group’s summary rows), to see which cell covers each position. These are the grids validation checks spans against. Each cell gets a code (A, B, …, Z, AA, …), and a position shows the code of the cell that covers it, so a span is a run of one code; . is a position nothing covers. The spanning cells are listed under each grid, then the section’s span errors, marked !.
An invalid table is drawn too, and the exit code is 0 whenever the IR parses. A section with a row of the wrong length isn’t drawn (that’s a COL_COUNT error, which gridwell validate reports).
gridwell grid [INPUT]Example output
$ gridwell grid spanners.json
thead: 2 rows, 3 columns
c0 c1 c2
r0 [A ][B ][B ]
r1 [A ][C ][D ]
A = cell(r0,c0, rowspan=2) "Name"
B = cell(r0,c1, colspan=2) "Scores"
tbody group 0: 2 rows, 3 columns
c0 c1 c2
r0 [A ][B ][C ]
r1 [D ][E ][F ]
$ gridwell grid broken_table.json
thead: 1 row, 3 columns
c0 c1 c2
r0 [A ][B ][C ]
tbody group 0: not drawn, row 0 has 4 cells but config.table_cols is 3
tbody group 1: 1 row, 3 columns
c0 c1 c2
r0 [A ][B ][C ]
C = cell(r0,c2, colspan=2) "7"
! [SPAN_OVERFLOW_RIGHT] Cell at tbody group 1 (row=0, col=2) has colspan=2 but table only has 3 columns (would need col index up to 3)gridwell formats
List all supported output formats.
Example output
$ gridwell formats
Supported output formats:
Text formats:
html HTML5 table (.html)
latex LaTeX tabular / longtable (booktabs) (.tex)
typst Typst table markup (.typ)
rtf Rich Text Format (.rtf)
svg SVG image (standalone, measured layout) (.svg, experimental)
ansi Terminal output with box drawing and ANSI colors (.txt, experimental)
pandoc Pandoc JSON AST (Table block) (.json, experimental)
quarto Quarto-flavored Pandoc JSON AST (cross-referenceable Div) (.json, experimental)
Binary formats:
docx Microsoft Word document (.docx)
xlsx Microsoft Excel workbook (.xlsx)
pptx Microsoft PowerPoint slide (.pptx)
Experimental formats write valid output with every cell, but their styling
is best-effort and may change between releases.
Pass writer options with --options '<JSON>'; see `gridwell formats --json`.gridwell formats --json prints the same list as JSON, including each format’s extension, media type, whether it is experimental, and options with their defaults.
gridwell conformance
Check a table IR against an expected table, for an emitter’s tests (the conformance kit is in the repository’s conformance/ directory; see its README). Tables are compared as normalized grids, by tiers: L0 valid, L1 structure, L2 content, L3 styling, each including the ones before.
gridwell conformance normalize [--tier <TIER>] [INPUT]
gridwell conformance check [--tier <TIER>] [--json] <INPUT> <EXPECTED>normalize prints a table’s grid (to L3 unless --tier says otherwise); an invalid table is an error. check compares the table’s grid with an expected one, to the expected grid’s tier unless --tier asks for less, and exits with code 1 when it doesn’t conform (IR that doesn’t parse or validate fails L0). --json prints the report as JSON.
Example output
$ gridwell conformance check reformatted.json conformance/expected/gt/exibble_basic.json
fails L1 (checked to L3)
L0 valid: pass
L1 structure: fail (1 difference)
L2 content: fail (1 difference)
L3 styling: fail
2 differences:
L2 groups[0].rows[0].cells[0].runs[0].text: expected "1.111e-01", got "0.1111"
L1 groups[0].rows[0].cells[0].text: expected "1.111e-01", got "0.1111"gridwell schema
Print the JSON Schema of the IR this gridwell writes, for an editor or another language’s validator to check IR against. Redirect it to a file (> ir-1.0.schema.json) to keep it.
gridwell schemaFormat Values
Format names are case-insensitive. An unknown name is an error that lists the supported ones.