Converting Markdown Files

Published | Go Back

Recently, I’ve found an ac­cept­able work­flow for con­vert­ing a mark­down file to a non-mark­down-fash­ioned doc­u­ment.

I’ve been us­ing mark­down for­mat for writ­ing doc­u­ments lately. I use head­ing level one for ti­tle and level two for the top-level sec­tions”. One prob­lem is that some­times I need to con­vert the doc­u­ment to a non-mark­down-fash­ioned for­mat like Google Doc. I tried ren­der­ing the mark­down file in styled HTML and then copy-past­ing the re­sult in Google Doc di­rectly. The re­sult looks OK, but the ma­jor prob­lem is that the head­ing lev­els are off by one, and I have to man­u­ally change them.

Then I found pandoc. It is not rarely known per se, but I found a very use­ful op­tion called --shift-heading-level-by=-1. This solves my prob­lem men­tioned above ex­actly. All head­ing lev­els are shifted by one, and the head­ing level one used as the ti­tle in my mark­down doc­u­ment is re­moved.

Now my work­flow looks like this. I write in mark­down for­mat, use pandoc to con­vert it to raw HTML for­mat with head­ings shifted by one, and fi­nally copy-paste the HTML from browser to Google Doc. Google Doc can rec­og­nize and match most of the HTML tags to its built-in styles, ex­cept for the code style. This is to­tally ac­cept­able for me be­fore I en­counter bet­ter so­lu­tions.