SKILL.md
# Markdown Table
Turn pasted CSV, TSV, or JSON into a clean, properly-aligned GitHub-flavored
markdown table.
## When to use
Use this skill whenever the user pastes tabular data and asks to:
- "format as a table"
- "make this a markdown table"
- "clean this up"
- "tabulate this"
Also use it when the user pastes CSV/TSV/JSON and provides no instruction
but the data is clearly tabular.
## Inputs
The user will paste one of three shapes:
1. **CSV** — comma-separated, optionally quoted, with or without a header row.
2. **TSV** — tab-separated.
3. **JSON** — array of objects (rows) or object of arrays (columns).
Optional flags from the user:
- `align`: `left` | `center` | `right` per column, or one global value.
- `headers`: explicit column names if the input has none.
- `limit`: max rows to render (truncate with a "…and N more" footer).
## Output format
A single fenced or unfenced markdown table:
```
| Header A | Header B | Header C |
|----------|---------:|:--------:|
| value | 1 | yes |
```
Rules:
- One pipe at start of each row, one at end.
- The separator line uses `---` for left, `---:` for right, `:---:` for center.
- Pad each cell so columns visually align in the source. This costs nothing and
makes the raw markdown readable.
- Numbers right-align by default. Booleans center. Strings left.
- Never wrap a value across lines. If a cell contains a newline, replace with `<br>`.
- Pipes inside cells are escaped as `\|`.
- Empty cells render as a single space, not "null" or "—".
## Process
1. Detect format. CSV vs TSV: if there are more tabs than commas in the first
line, assume TSV. JSON: starts with `[` or `{`.
2. Parse rows. Honor RFC 4180 quoting for CSV.
3. Detect headers. If row 1 has all-string cells but row 2 has a number, row 1
is probably a header. If unclear, ask once.
4. Detect column type for alignment: numeric, boolean, or string.
5. Render. Pad to widest cell per column.
6. If `limit` is set or rows > 50, truncate and add a footer line:
`_…and N more rows_`.
## Examples
**Input (CSV):**
```
name,population,country
Tokyo,37400000,Japan
Delhi,28500000,India
Shanghai,25600000,China
```
**Output:**
```
| name | population | country |
|----------|-----------:|---------|
| Tokyo | 37400000 | Japan |
| Delhi | 28500000 | India |
| Shanghai | 25600000 | China |
```
**Input (JSON):**
```
[{"sku":"A1","price":12.5},{"sku":"B2","price":7}]
```
**Output:**
```
| sku | price |
|-----|------:|
| A1 | 12.5 |
| B2 | 7 |
```
## Hard rules
- Never re-order columns unless the user asks.
- Never re-order rows unless the user asks.
- Preserve original cell content byte-for-byte (other than escapes).
- If you cannot parse the input, say "I can't tell what format this is — is it CSV, TSV, or JSON?" and stop.