Convert a Markdown text file into a Google Document using Appscript?
Asked Answered
O

8

80

I am trying to migrate a load of documentation which was written in markdown into a Google Doc so it can be used by our marketing department.

Is there a mechanism using appscript/ Google Docs Api that I can import a file and convert it to a Google Doc using a predefined template? Eg H1s will map to Title, etc

Overwhelming answered 29/6, 2019 at 19:12 Comment(2)
Although I'm not sure whether this is the direction you want, as one of several workarounds, how about using Markdown API of GitHub? It can think of the following flow. 1. Upload the markdown file to Web Apps of Google side. 2. At Web Apps, the retrieved file is converted to HTML using Markdown API of GitHub and converted to Google Document. It might be required to modify the Document for the template. I'm not sure about your template, the number of files and the maximum file size. So if this was not the direction you want, I apologize.Tragacanth
Did you ever find a way to do bulk conversions from Markdown into Google Docs? I currently convert individual documents by pasting Markdown into a Markdown editor (e.g. dillinger.io) then copying the formatted text — but obviously that doesn't scale!Embed
E
55

One suggestion: use Pandoc to convert Markdown to docx, then import to Google Docs using the Google Drive API.

You can also accomplish this using the Google Drive web interface:

  1. Convert markdown to ODT (or some other intermediate) using pandoc: pandoc MyFile.md -f markdown -t odt -s -o MyFile.odt
  2. Move the ODT file into your Google Drive folder.
  3. Right-click the ODT file (in the web version of Drive) and press "Open With -> Google Docs".
  4. Google Drive will now create a new Google Doc, with contents matching the ODT file, and open it for you.
Embed answered 16/9, 2020 at 9:31 Comment(1)
I wonder why not convert directly to Docx instead of odtForbidding
D
86

Easiest way that most likely requires no new tooling for many developers (if you're willing to do some manual pasting):

Just use Visual Studio Code.

  1. Paste text into the editor.
  2. At bottom right, select markdown as language.
  3. Top right, click the preview button.
  4. This will split the screen and show the rendered markdown you can paste into google docs.
  5. It's pretty quick at this point to just keep paste markdown/copy result/repeat as long as you don't have hundreds of docs.

Of course, if it's a ton of docs, you'll want something more automated than this.

Distortion answered 16/11, 2021 at 1:14 Comment(6)
Haha, I'm happy it helped you. I use the markdown stuff in VSCODE a ton, so was happy when I saw that it worked for google docs.Distortion
Thanks! After pasting into google docs, I found it helpful to highlight all the text and then select Format > Clear formatting (⌘\).Pyromancy
vscode is god... also much prettier than those internet converter things' resultsHysteria
Great tip! RStudio is also a good program for doing this—just open the file and click the 'Preview' button.Tsai
You can use the Add on Docs to Markdown Pro. It can directly insert Markdown or HTML into Google Docs and later also helps you convert Google Docs into Markdown.Legrand
this is the way for going from markdown native copy to easily pasting with formatting in google docs. "meets the requirements"Jennyjeno
E
55

One suggestion: use Pandoc to convert Markdown to docx, then import to Google Docs using the Google Drive API.

You can also accomplish this using the Google Drive web interface:

  1. Convert markdown to ODT (or some other intermediate) using pandoc: pandoc MyFile.md -f markdown -t odt -s -o MyFile.odt
  2. Move the ODT file into your Google Drive folder.
  3. Right-click the ODT file (in the web version of Drive) and press "Open With -> Google Docs".
  4. Google Drive will now create a new Google Doc, with contents matching the ODT file, and open it for you.
Embed answered 16/9, 2020 at 9:31 Comment(1)
I wonder why not convert directly to Docx instead of odtForbidding
E
35

No add-ons needed

I just stumbled upon a really simple approach that may suit your needs.

In github, I opened a ReadMe.md file, rendered in the browser as rich text. I copied it from the browser and pasted it into a new Google Doc.

Voila: Google Docs preserved the headings, bullets, etc. I can't vouch for what it does with links and other fancier markdown ops, but it was a quick way to get started.

Egide answered 6/10, 2021 at 13:13 Comment(3)
Can you describe for posterity how to render an .md file in the browser as rich text?Dispense
@Dispense Assuming your .md file is already on github, you just view it -- github will render it as rich text. If it is not on github,, you can push it to one of your repositories or if you don't want to do that, use one of the non-github solutions offered here.Egide
caveat: This won't work for large md files.Immobilize
D
14

One variation of the suggestion to use pandoc: try using the docx format instead of odt. Google Docs handles MS Office files natively so I found formatting was preserved somewhat better using this approach.

Revised steps:

  1. Convert markdown to DOCX using pandoc: pandoc MyFile.md -f markdown -t docx -s -o MyFile.docx
  2. Upload MyFile.docx into your Google Drive folder
  3. Double-click MyFile.docx in the web version of Drive
  4. Google Drive will open MyFile.docx in a new tab
Daemon answered 18/7, 2021 at 16:15 Comment(1)
this seems better than odt.Werth
G
4
#!/bin/bash

# Create the "converted" directory if it doesn't already exist
if [ ! -d "converted" ]; then
  mkdir "converted"
fi

# Find all markdown files in the current directory and its subdirectories
find . -name "*.md" | while read filename; do
  # Use pandoc to convert the file to a .docx file
  pandoc "$filename" -o "${filename%.*}.docx"

  # Create the same directory structure under "converted" as the original file
  dir=$(dirname "$filename")
  mkdir -p "converted/$dir"

  # Move the converted file to the "converted" directory
  mv "${filename%.*}.docx" "converted/$dir"
done
Gloat answered 2/1, 2023 at 21:22 Comment(0)
E
3

I don't know of a tool or library that allows for a direct conversion from markdown to a google doc.

Maybe you can convert your markdown to an intermediary format compatible with Google Docs (viable formats include .docx, .docm .dot, .dotx, .dotm, .html, plain text (.txt), .rtf and .odt) and then go from there.

You just need to find a tool that can convert markdown to one of those formats and also process your files in bulk (maybe some command-line utility could help with that).

Expatriate answered 29/6, 2019 at 19:23 Comment(0)
H
0

There is the Google Docs Addon Markdown to Docs ... which converts Markdown to Google Docs.

It has its limitations due to the Gdoc format but works otherwise very well.

Hyksos answered 10/6, 2021 at 19:25 Comment(0)
V
0

Alternative to manual pasting, if you don't want to use Github or VSCode, is that you can go to https://markdownlivepreview.com/ and paste your markdown there to get a preview of the formatted version. Click on the preview and select all with Ctrl-A, then copy with Ctrl-C.

Then paste it into Google Docs and the formatted version will be pasted there.

Vander answered 12/7, 2024 at 11:0 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.