I'm developing a Google Doc add-on with Apps Script. When clicking on a button, I want to highlight (underline or set a different background color) some given words in the entire document.
I know how to format text with Apps Script. I could underline the words with
text.setUnderline(true)
but in that case it would underline the text changing its actual format in the document. I'm looking for a way to highlight (again, underline or set a background color) the words without changing the internal content of the document. In other words, I don't want the highlights to be persisted for the future.
To better understand what I'm asking, the new format of the highlighted words must not be present when printing the document or sharing it with another user who has not installed the add-on.
The idea is to develop a custom spell/grammar checker, and I want to highlight the misspelled or incorrect text as the Google Docs' integrated spellchecker does, without persisting the red underlines in the document.
Notes:
The question is similar to this one and this one, but for Apps Script instead of Microsoft Office API.
I've been suggested to use "suggested edits", referring to this question. I'd like to note this is not what I'm looking for, because the suggested edits would be persisted and they would be visible for anyone opening the document, having my add-on installed or not.