4

It's possible to retrieve elements of an open Google Docs document, starting from

DocumentApp.openById(doc_id, folder_id)

but the comments on a document are retrieved through the Drive API, with Comments.list

Running this on a document with 2 comments: one on an image, one on a word in a paragraph shows that while text-anchored comments do, images don't return a context entry:

 "content": "test comment on text",
 "deleted": false,
 "status": "open",
 "context": {
  "type": "text/html",
  "value": "some text the comment is placed on"
 },
 "anchor": "kix.xxxxxxxxxxx1",

 "content": "test comment on an image",
 "deleted": false,
 "status": "open",
 "anchor": "kix.xxxxxxxxxxx2",

where xxxxxxxxxxx1/xxxxxxxxxxx2 are the unique anchor ID suffixes, and kix the prefix for Google's "proprietary" anchoring/editor system (as Steven Bazyl described it in the video on the "Managing comments and discussions" developer guide page).

"The anchor basically tells us where in the document this comment applies to. Because this is our format [at Google] we do have a proprietary anchoring scheme, which does make it difficult — or rather, impossible — for you to curatecreate? comments that are anchored to text in our document formats... but if it's a document format that you control, or if it's something where uh.. there are ways to locate it in an interchangeable way, you can put anchors in there that your app can position correctly, and potentially that other apps could read and position correctly as well."

If I can't see the element a comment is placed on, is an attempt to store an image source URL in a comment on the corresponding image doomed? (context: making a .gdoc-to-.md converter)

If so, might the only way to match comments to images be to retrieve all context field-less comments and assume every image to be commented?

  • GitHub doesn't list Google Apps Script as a language (presumably because it's based so closely on Javascript). Are there open source examples of custom comment anchoring systems I could take a look at?

  • If I were to write something with the Drive comments SDK (as Steven suggested), is there any way this could override the built in Google Docs commenting (such that Ctrl/Cmd + M or a custom button made a comment on an image with a GAS-accessible context) ?

Community
  • 1
  • 1
Louis Maddox
  • 5,226
  • 5
  • 36
  • 66

1 Answers1

1

Simple answer is you can't match reliably. The anchors simply aren't exposed in the Document API anywhere. If they were exposed, I'd expect them to appear as NamedRange or Bookmark entries, but neither appears populated by comment anchors.

Steve Bazyl
  • 11,002
  • 3
  • 21
  • 24
  • Thanks for the reply Steve - that's too bad. For now I'm going with setting a link (since `LINK_URL` is accessible) on the image, making a comment with the identical link (giving matching 'keys' of a sort), then replying to the comment with the further information I would want to attach to the image (clicking `Resolve` to hide the thread from view). Presuming the Document API isn't in for an upgrade (and this isn't seen as a bug?) I'm curious whether a custom comment schema as you've suggested could be made visible in the same way as the built-in comments. My intuition suggests they'd not be. – Louis Maddox Mar 20 '15 at 21:16