DEV Community

Ceco Gatev
Ceco Gatev

Posted on

Stop hand-aligning Markdown tables

Markdown tables are great until you're lining up pipes by hand in a README. Two things that save me every time:

1. The alignment row controls columns, not your spaces

You do not need the cells visually aligned in the raw text — renderers don't care. This renders fine:

| Name | Role | Status |
| :--- | :--- | :--- |
| Ada | Founder | Active |
Enter fullscreen mode Exit fullscreen mode

The second row sets alignment:

  • :--- left, :---: center, ---: right.

So stop padding with spaces — it changes nothing in the output.

2. Generate from data instead of typing

Most table data already lives in a spreadsheet or CSV. Pasting from Excel/Sheets gives you tab-separated text; a tiny script turns it into a table:

const toMd = (tsv) => {
  const rows = tsv.trim().split('\n').map(r => r.split('\t'));
  const head = `| ${rows[0].join(' | ')} |`;
  const sep  = `| ${rows[0].map(() => ':---').join(' | ')} |`;
  const body = rows.slice(1).map(r => `| ${r.join(' | ')} |`).join('\n');
  return [head, sep, body].join('\n');
};
Enter fullscreen mode Exit fullscreen mode

(Remember to escape literal | inside cells as \|.)

If you just want to paste-and-copy without the script, I put up a free one that auto-detects comma vs tab and lets you pick alignment: https://tsetsobg.github.io/tools/markdown-table-generator — runs in the browser, nothing uploaded. Same place has a JSON formatter for the other half of README pain.

What's your most-hated Markdown chore — tables, or escaping code blocks inside code blocks?

Top comments (0)