steverhall / sort-markdown-table

Sorts tables inside a markdown file, replacing file if successful.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sort-markdown-table

Sorts markdown tables

Markdown

To sort markdown, a comment must be added before the table (it can be anywhere in file before the table). The comment is:

<!-- sorted -->

Example

<!-- sorted -->
| Italian   | English | Emoji |
| --------- | ------- | --- |
| Mela      | Apple   | 🍎 |
| Arancia   | Orange  | 🍊 |
| Aglio     | Garlic  | πŸ§„ |
| Cane      | Dog     | 🐢 |
| Gatto     | Cat     | 🐱 |
| Piatto    | Plate   | 🍽 |
| Bicchiere | Glass   | πŸ₯› |
| Burro     | Butter  | 🧈 |
| Pane      | Bread   | 🍞 |

results in:

Italian English Emoji
Aglio Garlic πŸ§„
Arancia Orange 🍊
Bicchiere Glass πŸ₯›
Burro Butter 🧈
Cane Dog 🐢
Gatto Cat 🐱
Mela Apple 🍎
Pane Bread 🍞
Piatto Plate 🍽

Command Line Usage

Sort tables marked with <!-- sorted --> and send output to stdout.

gawk -f sort-markdown-table.awk [input-file]

About

Sorts tables inside a markdown file, replacing file if successful.

License:MIT License


Languages

Language:Awk 85.5%Language:Shell 14.5%