Convert Google Docs to Jekyll Markdown
Asked Answered
R

4

22

How can I convert a Google Docs, which contains images and tables, into a Markdown file which can be published as a post using Jekyll?

Is it possible to first export the Google Docs into a PDF and then convert the PDF to Markdown? What will happen to the images and tables in that case?

Ranch answered 4/11, 2013 at 14:7 Comment(6)
You're asking a lot here, and there's really no way to achieve this. Google docs is for document editing, and so it concerns itself with formatting and layout. Markdown and Textile are for text entry, and don't really put too much emphasis on visual stuff. There would be no way to convert from one to the other without a significant loss of fidelity.Washington
Thanks Brian. I already expected that a conversion would not be without losses. However, I sometimes do collaborative paper writing in Google Docs and want to publish the final results on my Jekyll blog. So, if you were asked to convert it (given the losses) which approach would you choose?Ranch
Honestly, I'd consider teaching the people I was working with how markdown works. It's pretty straight forward for even non-technical people to understand. Other than that, you might be stuck with modifying documents by hand.Washington
Thanks. I will have to see if I can get them motivated to dig into Markdown.Ranch
Another alternative which I have found - but which does not have anything to do with converting - is to simply embed the PDF using the embedding as iframe feature from Google Drive, described here. The result is actually very neat and clean. See this example.Ranch
See also How can Google Docs and markdown play nice? - Web Applications Stack ExchangeSverdlovsk
L
32

May 2018 Update

The script originally suggested in this answer appears to no longer work and has not been updated for 5 years.

An alternative solution (which is based on the old script) can be found at https://github.com/evbacher/gd2md-html

I tried it out, it works pretty well.

Previous Answer

You can use a Google Script to do the conversion for you!

This one will let you convert to .md and it will email you the converted file. I've tested it and works fine. It works with basic tables, and if you have images in the doc, it will attach them to the email.

Instructions for installing are on the same link, in the GitHub description, but I pasted it here for ease of access:

Add the script:

  • Open your Google Drive document (http://drive.google.com)
  • Tools -> Script Manager > New
  • Select "Blank Project", then paste this code in and save.
  • Clear the myFunction() default empty function and paste the contents of converttomarkdown.gapps into the code editor
  • File -> Save

Run the script:

  • Tools > Script Manager
  • Select "ConvertToMarkdown" function.
  • Click Run button (First run will require you to authorize it. Authorize and run again)
  • Converted doc with images attached will be emailed to you. Subject will be "[MARKDOWN_MAKER]...".

Good luck!

Lavonda answered 14/2, 2014 at 23:14 Comment(2)
This should now be the accepted answer. The Mangini script works really well except for some embedded images (I've lodge an error report).Dessiedessma
Great approach, thanks! I made it the accepted answer.Ranch
L
1

You can export as HTML. Jekyll can serve static HTML files.

Btw, "standard" markdown doesn't have tables. There are implementation that have it, but I'm afraid you'll have to convert them by hand to the right format, which will be implementation dependent. I don't know about Jekyll, maybe it's easiest to just use HTML tables within the markdown text.

You could create a new theme based on the HTML export. The export should contain the stylesheet embedded in a <style> tag within the HTML document. It's not really easy to create new themes, but doable. Or, if you just want the content and don't mind using whatever Jekyll theme you already have, then you can cut out the stylesheet part and keep the html only.

Lasandralasater answered 2/12, 2013 at 22:30 Comment(3)
Thanks janos. When you export as HTML, then obviously it will not nicely integrate into the theme and template design used by the specific Jekyll application, correct? This is then of course a drawback.Ranch
@Ranch I added a new paragraph to respond to that.Lasandralasater
Thanks! Probably the best approach so far.Ranch
T
0

Another option would be to change how files are delimited in Excel on your computer. This guide can help you do that (http://www.howtogeek.com/howto/21456/export-or-save-excel-files-with-pipe-or-other-delimiters-instead-of-commas/)

Then every time you copy and paste from excel to a markdown file/jekyll you automatically have the pipes. All you will need to do is add some dashes to separate your topline..

Touchwood answered 25/1, 2015 at 17:0 Comment(0)
C
0

Google Docs -> docx to Markdown -> md

I myself looked far and wide but I believe the best way to do this is by using Pandoc.

Works for all platforms (check their incredible website ) , what you are looking for is the following command on your cmd or PowerShell (Windows) :

pandoc input_filename.docx -s -o output.md

Pro Tip: Pandoc comes with a little trick to store up even all of the images in your document to your custom folder and then adding the image tags in the markdown by using relative referencing to those images at the correct places. The amazing line of code is:

pandoc --extract-media ./your_custom_folder input_filename.docx -o output_filename.md
Corbel answered 28/9, 2020 at 18:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.