Bulk Org-Mode to Github Flavored Markdown
14 Apr 2019
I wanted to move my raw notes for blog post entries from org-mode into a markdown format suitable for ingestion by Jekyll. While you could do single exports of each org file, and then copy-paste as posts are written, this seemed inefficient and difficult to make after-conversion changes. So, I set about a way to convert a set of org files into a corresponding set of markdown files. My initial approach was to use elisp to bulk script the org-mode export. I then wrapped this in a shell script which moved the files to the destination folder. However, I ended up settling on an approach of using pandoc to convert the files wrapped in a shell script. This appears to be the superior approach since it only requires one script file and less variable maintenance. I’ll leave both approaches in the post on the office chance the former works better.
Environment and Dependencies
- emacs 26.1
- with org layer (contains ox-gfm)
- pandoc 2.6
Initial approach (elisp + shell script)
Shell script at
Wrapping shell script, embedded at
- I was never able to get
ox-gfmto load properly and ended up embedding it in the script.
- org files at
~/org/blog, blog source is at
Final approach (pandoc shell script)
Shell script placed at
This script first creates a similar folder structure to the source
folders. As a second step, it looks through the source for org files and
creates the destination
md path via substitution with
sed. If you
are interested in debugging the output paths substitution (since this
fairly specific to my setup),
It then passes these output paths to pandoc (set to use github flavored markdown with a table of contents and no line wrapping).