Last active
August 29, 2015 14:06
-
-
Save mattantonelli/733ded40f5c84336a5b0 to your computer and use it in GitHub Desktop.
Converts CSV to Github table markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 + '---') |
Author
mattantonelli
commented
Sep 15, 2014
a | b | c |
---|---|---|
d | e | f |
g | h | i |
Alternate solution:
https://gist.github.com/TrevorS/b0b45c3ecc4048ad17a7
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment