1

Say we have a CSV in a buffer:

foo,bar,hello
1,234,95
8923,901,145

Are there any native Emacs or Markdown-mode built-ins in Emacs that can be used to convert it to a Markdown table? It looks like the syntax is quite different:

| Tables        | Are           | Cool  |
| ------------- |:-------------:| -----:|
| col 3 is      | right-aligned | $1600 |
| col 2 is      | centered      |   $12 |
| zebra stripes | are neat      |    $1 |
  • Would a series of regex replacements work, or do you want something less general? – PythonNut Aug 11 '15 at 17:44
  • An idea: select the region containing the csv content, then M-x org-table-create-or-convert-from-region (to do this org mode should be enabled), in this way you obtain an org-table. Then there is the command M-x org-md-export-as-markdown. I am not sure if this output is the one you would like to obtain. – Name Aug 11 '15 at 18:30
1

The Melpa package archive has markdown-mode. My currently installed version is markdown-mode-20180115.1905. If you have added melpa to package-archives correctly you can install markdown-mode via M-x package-install.

After installation of markdown-mode files with extension .md are opened in markdown-mode.

If that mode is activated you find the submenu Tables in the Markdown menu. In there you find the menu item Convert Region to Table.

If you click that item after selecting the cvs table as region the cvs table is converted to a markdown table.

It is easy to add a header line. Just insert a newline after the first line, type |- and press Tab. The initial string |- is expanded to a full header line.

You only need to add the colons : yourself. Each time you modify the table in that way you can re-balance the table by pressing Tab.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.