wooorm/markdown-table

Stop showing colons when align right/center

rnwolfe opened this issue · 2 comments

Hello, this might be pretty rudimentary, but figured I'd ask. I'm using this to create more of a text-table that gets put in a pre-formatted block (where it ends up doesn't support MD tables) rathen than to create Markdown formatting.

So, I don't really need the : to do alignment, but still want to use alignment. The : ends up throwing off the otherwise clean look. This is easy/quick to fix:

https://github.com/wooorm/markdown-table/blob/master/index.js#L21

var COLOR = ':'

to

var COLON = '-'

But, is there a better way to stop showing : when alignment is right/center?

Doesn't seem to be from my reviewing the code. Not sure if it's worth a PR to add a passable option given using this as a text-table tool is not the direct purpose of the module? Let me know!

Technically, we could of course add an alignCharacter, that defaults to :.

But I do feel a bit weird about adding this to a project named markdown-table (although we support some non-markdown options): this project should focus on markdown and stay small in size and functionality.

As any : could only be in the second row (between the first and second \n), you could replace them? Something like this (pseudocode):

var lines = markdownTable(...).split('\n')
lines[1] = lines[1].replace(/:/g, '-')
var doc = lines.join('\n')

Yea, fair enough. Keep the module clean and concise.

Based on your suggestion, to keep from changing the module, I made up this quick function (really, you did 😄) should anyone else stumble here.

function removeColons(table) {
  var lines = table.split('\n')
  lines[1] = lines[1].replace(/:/g, '-')
  return lines.join('\n')
}

You can then just wrap it around your table:

var plain = removeColons(markdownTable(...));

Thanks!