This is a test paragraph with a link in the middle of it.
This is a test paragraph with a link in the middle of it.
This is a test paragraph with a link on the whole sentence.
This is a test paragraph with a link in the middle of it.
This is a test paragraph with a link on the whole sentence.
function myFunction() { var body = DocumentApp.getActiveDocument().getBody(); var childNum = body.getNumChildren(); var linkStyle = {}; linkStyle[DocumentApp.Attribute.FOREGROUND_COLOR] = "#FF0000"; linkStyle[DocumentApp.Attribute.UNDERLINE] = true; for(var i=0; i<childNum; i++){ var par = body.getChild(i); var link = par.asText().getLinkUrl(); Logger.log(link); if(link !=null){ par.setAttributes(linkStyle); } }
}
for(var i=0; i<childNum; i++){
var par = body.getChild(i);
var link = par.asText().getLinkUrl();
Logger.log(link);
if(link !=null){
par.setAttributes(linkStyle);
}
}
for (var i = 0; i < childNum; i++) {
var par = body.getChild(i);
var text = par.asText();
var t = text.getText();
var temp = {};
for (var j = 0; j < t.length; j++) {
var link = text.getLinkUrl(j);
if (!("start" in temp) && link) {
temp.start = j;
} else if ("start" in temp && !("end" in temp) && !link || j == t.length - 1) {
temp.end = j;
}
if ("start" in temp && "end" in temp) {
text.setAttributes(temp.start, temp.end, linkStyle)
temp = {};
}
}
}