I'm writing an app script and I'm trying to make a function that highlights a particular piece of text. The result of the code is that I'm highlighting the entire line instead of just the text.
Before:
After:
What I want:
Here is my code:
function myFun4(){
var selection = DocumentApp.getActiveDocument().getSelection();
if(selection){
var el = selection.getRangeElements();
Logger.log(el[0].getElement().getAttributes());
var el0 = el[0].getElement();
Logger.log(el0.asText());
var highlightStyle = {};
highlightStyle[DocumentApp.Attribute.BOLD] = true;
highlightStyle[DocumentApp.Attribute.BACKGROUND_COLOR] = '#FFFF00';
el0.setAttributes(highlightStyle);
}
}


