Skip to content

Instantly share code, notes, and snippets.

@januridp
Created February 7, 2025 03:45
Show Gist options
  • Save januridp/24fef062fed93c547ff76069c06ecc9e to your computer and use it in GitHub Desktop.
Save januridp/24fef062fed93c547ff76069c06ecc9e to your computer and use it in GitHub Desktop.
Google App Script for Highlight Words
function highlight_words() {
var doc = DocumentApp.getActiveDocument();
var words = ['DONE','WIP'];
var styleDone = { [DocumentApp.Attribute.BACKGROUND_COLOR]:'#9bcb98' }; //light-green
var styleWIP = { [DocumentApp.Attribute.BACKGROUND_COLOR]:'#ffc182' }; //light-orange
var pgfs = doc.getParagraphs();
for (var word of words) for (var pgf of pgfs) {
if (word === 'DONE') {
var location = pgf.findText(word);
if (!location) continue;
var start = location.getStartOffset();
var end = location.getEndOffsetInclusive();
location.getElement().setAttributes(start, end, styleDone);
}
if (word === 'WIP') {
var location = pgf.findText(word);
if (!location) continue;
var start = location.getStartOffset();
var end = location.getEndOffsetInclusive();
location.getElement().setAttributes(start, end, styleWIP);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment