Extract all tables from a document
Goal: Get every table in a document as structured table objects, ready for further transformation (add a row, convert to CSV, reshape, …).
Prerequisites: The table module, via -A or nodes. Unlike the section module, import "table" must be written explicitly — it isn’t auto-imported.
Query
$ mq -A 'import "table" | table::tables' README.md
Or with nodes:
import "table"
| nodes
| table::tables
Input
| Name | Age |
| ----- | --- |
| Alice | 30 |
Output
| Name | Age |
| ----- | --- |
| Alice | 30 |
Notes
- Table objects print back as Markdown automatically in CLI output, so
table::to_markdownisn’t needed here. It is needed when using the table module from Rust or other embedding code, where table objects stay plain dicts — and sincetable::tablesreturns an array (there can be more than one table), narrow to a single table first:table::tables | first | table::to_markdown. - Chain
| firstaftertable::tableswhen you only want the first table, as the other table recipes in this Cookbook do.