Google-apps-script – How to place invisible placeholders in a Google Doc

google docsgoogle-apps-script

I'd like to put invisible placeholders in a Google Doc so that they can be found and the content changed. In HTML, this would be a <span id="name-of-placeholder">, with the item findable via "elem = document.getElementById('name-of-placeholder');" and the content could be changed like for DOM, as "elem.innerHTML = newContent;".

What is the best way to do similar things with a Google Doc?

EDIT: I find lots of "mail merge" techniques which use visible placeholders, but replace the placeholders with the resulting text. Then the placeholder is gone, and there is no easy way to find it again for future updates.

Best Answer

Google Docs doesn't have invisible placeholders at this time, but it has bookmarks. From the second reference:

// Insert a bookmark at the cursor position and log its ID.
 var doc = DocumentApp.getActiveDocument();
 var cursor = doc.getCursor();
 var bookmark = doc.addBookmark(cursor);
 Logger.log(bookmark.getId());

References
Using bookmarks in a document
Class Bookmark