Google Documents integration #28

bordaigorl opened this Issue Aug 10, 2012 · 7 comments

4 participants


Any chance to get this to work with Google Documents (aka Google Drive)?
I love this extension and I would really like to use it with my google docs: this would allow to easily adapt the appearance of the document elements without being constrained by google docs own styles/structure elements.
For example: there is no "code" style in google docs so the best you can do is manually select the font each time etc which is very unsatisfying.

An option would be to exploit the Google App Script framework but it does not seem to support injection of HTML+CSS into the document.

Any idea on how to do that?


This would be super cool, but I don't have any good ideas how to do it. If you inspect the DOM of a GDoc, it's pretty crazy, and if you just start replacing DOM elements your changes won't get saved (without proper kix- class names?). Well, that's what I've seen in my brief testing.

So, the approach I've used for webmail probably wouldn't work. Maybe Google App Script? I suspect that an official programmatic interface like that would be the best bet, but if it can't modify document content... dunno.

It certainly would be great to support Google Docs, but I don't see it happening any time soon (not by me, anyway). I'll leave this open to remind myself to look at it again, though.


+1: this would be amazing. Google Docs has great collaborative features, but I feel crippled when I try to author content in them.


Google docs is behaving nicely when pasting rich text content. Can't an idea be to cut the markdown text, convert it to HTML and store it into the clipboard, and then simulate a paste of this content ?


@Steren: Your paste idea is interesting, so I did some research into how feasible it is. And... it doesn't super hopeful. Basically: Chrome extensions can't trigger a paste. Also, it'll require extra (and unknown) effort to read the contents of the document (in order to get the Markdown). (Google Docs don't even use selections normally...)

I added my notes to the NOTES file, but I'll also paste them below.

  • Paste does work fairly well to get rendered Markdown into a Google Doc. (Although Paste vs. Paste and Match Style give different results.) Some massaging of the Markdown (<br> vs. <p>, maybe) might improve results.

  • Googling and experimentation suggests that pasting cannot be triggered from a Chrome extension. (Not to be confused with reading from the clipboard, which can be done in a background script.)

  • Pasting probably can be triggered in an old-style (non-Jetpack) Firefox/Thunderbird extension. But I suspect it can't be done in a Jetpack extension (as with Chrome).

  • (Probably also can't be done in a Safari extension.)

  • A common way for websites (including Github) to support copy-to-clipboard is to use Flash. The most popular seems to be ZeroClipboard -- but it doesn't magically provide pasting (even if I could figure out how to use it in an extension).

  • When pasting, the markdown-here-wrapper is lost. This means that reverting may not be possible (at the very least, it'll require another approach).

  • Copying arbitrary HTML to the clipboard is probably doable on all platforms (it is on Chrome, at least).

So, it seem that, at best, MDH could put the rendered Markdown HTML into the clipboard and then the user will have to manually paste it. This is not great, but is perhaps better than nothing.

Another really big outstanding question: Can MDH detect what's selected in the GDoc? Can it get the text? Can it change the selection? Can it delete or replace the selection? (Some simple getSelection() tests are not hopeful.)


I'm really just adding this for completeness, but...

There's probably some potential in using the Google Drive API. I'm not going to speculate on how or what it would look like, but you can read and edit documents with the API, so there's probably/maybe something that can be done with it.

Really, the best thing would if Google added Markdown rendering support to GDrive, as requested here.


Google Docs just release an add-ons feature.
It is using Google Apps Script to be able to alter the document's content. I guess using this method would be slightly easier than using the Google Drive API from an extension since everything is hosted and approved by Google.

I may give it a try if I find time.


That sounds promising!
I hacked together a simple gapp script some time ago to export markdown from gdocs.
It may be useful as a starting point.
You can find it here
It is based on a similar script that can be found at mangini/gdocs2md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment