Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(Multi)Markdown table to CSV/TSV [closed]

I've found some tools/scripts to convert CSV->(Multi)Markdown, but is there anything to do it in a reverse direction?

I really like tables in Markdown and together with SublimeText and TableEditor plugin it's really convenient --- add columns, tab through cells etc.

but, not everyone likes editing data in a text file, so I would like to convert it to ex. CSV and import to Spreadsheet (Google or Excel) for the others.

Is there anything that can do it automatically or should I create my own script/plugin for pandoc/RedCarpet...

like image 652
Simon Avatar asked Mar 20 '13 11:03

Simon


People also ask

What is Markdown CSV?

CSV is used for storing and exchanging data. Markdown is human-friendly markup language, which can be automatically translated to HTML.

How do I convert Markdown to Word?

If you already have a Markdown tool for producing HTML, open the HTML in a browser and copy/paste into Word. Alternately, just open the HTML file itself in Word then save as Word format. and if it is a github markdown, then directly view and copy-paste..

How do I paste a table in Markdown?

Paste the cells in the Table to Markdown paste area. You can right-click and select "Paste" or type Ctrl+V for Windows or Command+V for macOS.


2 Answers

Use this code.

import pandas as pd

file = open('yourmdfile.md')
data = []
for line in file.readlines():
   data.append(line.split('|'))  # provide more general splitter

df = pd.DataFrame(data=data)
df.to_csv('generated.csv')

like image 123
bikram Avatar answered Oct 05 '22 22:10

bikram


You can convert MD to CSV with the free tableconvert.com webservice

  1. Go to menu "Import"
  2. Go to tab "Markdown"
  3. Paste your MD table
  4. Click on "Import Data"
  5. Now you will see table in top area
  6. in the bottom area, select tab ",CSV" or tab "Excel"
  7. Copy the text in the text area
  8. In your Spreadsheet app, paste the text(*)

(*) Excel and format real CSV; it requires using GetData+delimiter(Import)

I am not a fan of webapps but unfortunately i was not able to find any app or plugin for text editors that can do this conversion

like image 40
Daniel Perez Avatar answered Oct 05 '22 20:10

Daniel Perez