Custom Google Docs comment anchoring schema - lmmx/devnotes GitHub Wiki

I'm trying to tackle the same problem as posed in this question and think the problem lies with trying to use seemingly plain-text designed anchors for Google Docs, which is not plain-text.

Anchors are tied to different regions for different types of files, and apps should support regions that make sense for the file types they manipulate. For example, anchoring comments to line numbers makes sense for plain text documents, while anchoring them to a horizontal and vertical position makes more sense for images.

I think what's going unsaid here is that there's no example been given for how to write an anchor for Google Docs: images and plain-text are only subsections of Google Docs, so seemingly a new class of region would be required (NB the comment schemes described are for any file accessed with Drive, so no specific consideration to Google Docs even though that's presumably their most common point of use).

None of the listed supported region classifiers seem appropriate:

  • rect - a rectangle in a two dimensional image.
  • page - a page number in a pdf or tiff or other document with pages. Should also be used for documents with page-like elements. Eg. sheet (for spreadsheets), slide, layer etc.
  • time - a duration of time in a video or other document with a time dimension.
  • txt - a range of text
    See also: [`Enum Attribute`](https://developers.google.com/apps-script/reference/document/attribute)
  • line - a specific line in a text file or any files with lines in it
    • comments are not attached to entire lines (and this also failed when I tested it with Google Docs, leaving unanchored comments)
  • matrix - a location in a matrix-like structure. Useful for defining row and columns in spreadsheet documents, or any other documents which have a row/column structure

Custom schemas

If you want to create a new class of region, you should namespace it by the app ID. For example, if your app has ID 1234 and creates a property called Slide, then the full classifier name would be 1234.Slide. That way if another app publishes another Slide, then the two would not collide. The blank namespace should only be used by Google-published classifiers.

The app ID is the first number in your client ID (obtained from the Developer's console). Since this is just a script for now, it doesn't appear as a project, but having enabled the advanced Drive API it does have a project accessible in the Script editor from Resources > Advanced Google Services > link at the bottom.

If so, go to APIs & auth > Credentials in the sidebar, and click the Create new client ID button (choosing 'Web application').

Client ID: 000000000000-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

App ID: 000000000000

It also appears when all user's apps are listed with Drive.Apps.list().items - but doesn't seem to be a way to "get currently running app's ID"...?

⚠️ **GitHub.com Fallback** ⚠️