4

I'm just learning about org-mode, and of course blown away by its sheer level of usability. I of course want to use it everywhere, so I want to create tables with it. Including tables in markdown-mode.

The problem I'm running into is that the row-and-column separators in org-mode look like + while in markdown-mode they look like |, so I don't end up with nice-looking tables on, say, Github.

Can orgtbl-mode be configured so that a separator row will look more like |---|---| instead of |---+---| ?

  • 1
    I'm afraid the answer is "no": "+" is hard-wired in several places in org-table.el. It should be pretty easy to write an exporter from Org to GitHub-flavored Markdown, though, and then you would not need markdown-mode! :-) (The vanilla Markdown exporter produces HTML code for tables.) – Constantine Dec 10 '14 at 19:35
  • 4
    Saying this in case you didn't notice: GitHub itself has a limited Org parser (which still has a bit more features than Markdown), so if you are doing this to design a readme for your GitBub repository, you may as well do it in Org. – wvxvw Dec 10 '14 at 21:06
  • 1
    @wvxvw You are right and I have noticed. I need the end format to be markdown for a number of reasons, unfortunately (one of them is I'm the only emacs user). – Trevoke Dec 11 '14 at 20:07
4

What I've found so far is this.

The "simplest" way is, as described in this stackoverflow answer and this gist, and as hinted by @Constantine in a comment, is to create a converter function and then use it.

I went a tad further in laziness (this might already exist somewhere, but hey, I've only got the one use case right now). So here's what I have:

The converter function

(defun orgtbl-to-gfm (table params)
  "Convert the Orgtbl mode TABLE to GitHub Flavored Markdown."
  (let* ((alignment (mapconcat (lambda (x) (if x "|--:" "|---"))
                   org-table-last-alignment ""))
     (params2
      (list
       :splice t
       :hline (concat alignment "|")
       :lstart "| " :lend " |" :sep " | ")))
    (orgtbl-to-generic table (org-combine-plists params2 params))))

Sample usage:

;; Usage Example:
;;
;; <!-- BEGIN RECEIVE ORGTBL ${1:YOUR_TABLE_NAME} -->
;; <!-- END RECEIVE ORGTBL $1 -->
;;
;; <!--
;; #+ORGTBL: SEND $1 orgtbl-to-gfm
;; | $0 |
;; -->

My lazy inserter

This is about the laziest piece of code I've written in years, but hey, it's gonna make sure that when I'm writing markdown, I'm really just writing markdown. I'll also welcome all improvements to this code.

Bonus: Github-Flavored Markdown, and Github's preview itself, doesn't show HTML-style comments, therefore this is completely transparent. Love it.

(defun stag-insert-org-to-md-table (table-name)
  (interactive "*sEnter table name: ")
  (insert "<!---
#+ORGTBL: SEND " table-name " orgtbl-to-gfm

-->
<!--- BEGIN RECEIVE ORGTBL " table-name " -->
<!--- END RECEIVE ORGTBL " table-name " -->")
  (previous-line)
  (previous-line)
  (previous-line))
  • (previous-line 3) would be shorter – Andrew Swann Sep 12 '17 at 14:58
1

You can hack org-table.el this way:

org-table.el
874c158
<            (hfmt1 "-%s-+"))
---
>            (hfmt1 "-%s-|"))           ; HACK: + ➔ |

Works for me.

I put in a feature request to make this configurable.

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.