Editing a Markdown File in Google Docs
When recently working on a markdown file, I needed a simpler way to quickly format and manipulate the whole document to suit my specific needs. I think it would have taken a considerable amount of time if doing it in a markdown editor like StackEdit or Dillinger. While these tools are excellent at what they allow you to accomplish, the functions I needed were limited to a paid option or simply not available in those tools.
I happened across an easier method to edit the document and wanted to share what I found. In order to import a markdown (.md) file into Google Docs, I used the Pandoc tool. Pandoc is a universal document converter that converts files from one markup format into many other formats, as noted in the image below.
Import Options
I found multiple ways to convert a markdown file and import it into Google Docs for editing.
Option 1
The first option is to use Pandoc locally to convert the markdown file to docx and then import it to Google Docs using the Google Drive API.
Option 2
The second method also locally converts the file and then accomplishes the task using the Google Drive web interface itself.
Conversion
- First, let’s convert the local markdown file to ODT (or another interim format) using the following pandoc command in Powershell. The standard format for the command looks like this:
pandoc [input format] ==reader==> [Pandoc AST] ==writer==> [output format]
- So, my command looks like this:
pandoc file.md -f markdown -t odt -s -o file.odt
- Now, move the
file.odt
to your local Google Drive folder (if using the Google Drive Desktop) or upload thefile.odt
into your Google Drive. - Once the upload is complete, right-click on the
file.odt
(in the web version of Google Drive) and select “Open With ⇒ Google Docs.” Google Drive will now create and open a new Google Doc, with the contents matching thefile.odt
.
Export
When the changes are complete in Google Docs, I export the edited file using the “Docs to Markdown” (GD2md-html) tool. This plugin converts the Google Doc to a simple, readable Markdown or HTML file.
To export the open document, follow the steps below.
- Select Add-ons > Docs to Markdown > Convert.
- Select the text to convert (the default setting selects the entire document).
- Next, click the Markdown or HTML button in the sidebar.
- Finally, cut-and-paste the converted output from the sidebar and paste it into a .md document of your choosing.
That’s it! This is an easy method to import/export a Markdown document from one format to another. Thanks for reading!
Note: I am sure the follow-up comments below may offer more and better options for accomplishing this task. :D