Skip to content

Instantly share code, notes, and snippets.

@mattantonelli
Last active August 29, 2015 14:06
Show Gist options
  • Save mattantonelli/733ded40f5c84336a5b0 to your computer and use it in GitHub Desktop.
Save mattantonelli/733ded40f5c84336a5b0 to your computer and use it in GitHub Desktop.
Converts CSV to Github table markdown
#!/usr/bin/env ruby
# encoding: utf-8
input = "a,b,c\nd,e,f\ng,h,i"
num_cols = input[0..input.index("\n")].scan(',').count
puts input.split("\n").map { |l| l.gsub(/ *, */, ' | ') }.insert(1, '---|' * num_cols + '---')
@mattantonelli
Copy link
Author

a b c
d e f
g h i

@mattantonelli
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment