Google-docs – way to create bookmarks using text? (something like Wikimedia markup)

google docs

Using Google Docs, when I click Insert > Bookmark I create a bookmark (duh!) in that place of the document, kind of a <a name="here">cursor</a>.

I have a few of these bookmarks in a document. I'd like to edit the document in an external editor (e.g., Notepad++) and paste it back to Google Docs, but then I face the problem of having to regenerate the bookmarks by hand.

Is there a way to indicate to the docs editor that I want a bookmark in a specific place?
I'm thinking of something like

== here ==  

and then

 [[#here|cursor]]

in Wikimedia style.

Best Answer

The short answer is: yes. Hurray!

The medium-length answer is: yes, if have mad skillz. Aww, shucks.

A more full answer

Through Google Apps Script, Google Docs is amazingly extensible. The lynchpin function you are seeking is aptly named addBookmark() (class description here). The function requires a passed value, however, and that is what will require some creativity.

In Pseudo-code, something like the following might work:

Prior to uploading the document to Google, designate the bookmarks you want with super-special-awesome markup that doesn't interfere with anything. Per your suggestion, let's pretend we know that enclosing in two equal signs will not cause you problems, so == Special text to bookmark ==. Upload the document. Run your script.

The script:

  1. Starting at the top of the file, search the text of the document for a string pattern that matches == [any text] ==
  2. When matching string is found, get the Position (class description here) of the text
  3. Use Position and run addBookmark(Position)
  4. Continue with search of text until end of file
  5. Announce the end of the script execution

For a competent programmer, this is not a particularly difficult task. Even though I can conceptualize the pseudo-code and read the class descriptions, if I tried to write this, I would certainly gain more gray hair.

Good luck!