gajus / table

Formats data into a string table.
Other
900 stars 77 forks source link

New Table Template - Markdown #53

Open GantMan opened 6 years ago

GantMan commented 6 years ago

Great existing table templates, but one key item that's missing is the Markdown table.

| 0A | 0B | 0C |
|----|----|----|
| 1A | 1B | 1C |
| 2A | 2B | 2C |
| 2A | 2B | 2C |
| 2A | 2B | 2C |
| 2A | 2B | 2C |
| 2A | 2B | 2C |

Results in cool stuff on github, like so:

0A 0B 0C
1A 1B 1C
2A 2B 2C
2A 2B 2C
2A 2B 2C
2A 2B 2C
2A 2B 2C

Would be nice if we could give users a copy/paste friendly table for github!

https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#tables

GantMan commented 6 years ago

This works as long as the width of each column is >=3 characters.


table(data, {
  border: { 
    topBody: '',
    topJoin: '',
    topLeft: '',
    topRight: '',
    bottomBody: '',
    bottomJoin: '',
    bottomLeft: '',
    bottomRight: '',
    bodyLeft: '|',
    bodyRight: '|',
    bodyJoin: '|',
    joinBody: '-',
    joinLeft: '|',
    joinRight: '|',
    joinJoin: '|' 
  },
  drawHorizontalLine: (index) => index === 1
})
GantMan commented 6 years ago

Shame I can't combine the drawHorizontalLine, I could do the PR to add the template.

Maybe it should return a full config that can be extended? Thoughts? Not sure how to take it from here.