How to match comments on an image using kix anchor (or not) in Google Docs

自古美人都是妖i 提交于 2019-12-28 13:57:14

问题


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?

    • I don't actually believe such an anchoring system would be possible with the current API. While an anchor is provided by the Comments.list method, Comments.insert only allows fileId, content, context.type and context.value: no possibility for unique anchoring IDs here.

    • Related attempt: Creating anchored comments programmatically in Google Docs

  • 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) ?


回答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.



来源:https://stackoverflow.com/questions/29050342/how-to-match-comments-on-an-image-using-kix-anchor-or-not-in-google-docs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!