2

I'm looking to do the following:

  1. Locate links in the document
  2. Select them and change their styling

So far, I have:

var body = DocumentApp.getActiveDocument().getBody();
var text = body.editAsText().getText();
var words = text.split(' ');

for (var i = 0; i < words.length; i++) {
  var word = words[i];
  // Doesn't work because word isn't a Text object
  // word.getLinkUrl();
}

I understand how to iterate over the words in a paragraph. The issue is determining if the text is a link. I can't use the getText() method because that converts the Text object to a string (prohibiting me from testing if a word is a link via the getLinkUrl() method.

I've found a number of "find and replace" solutions. I can't use findText() because I can't predict the strings in the links. For instance, Resources could point to example.com.

Any help would be much appreciated.

Community
  • 1
  • 1
SwankyLegg
  • 473
  • 4
  • 14
  • You'll need to improve your question. How do you want to style the links? Have you tried to write a function that just styles a link? That seems to be the block. – Alan Wells Jan 15 '16 at 22:26
  • Styling the links is a non-issue. The problem is that I can't select the links that are currently in the document. Updating the question now. – SwankyLegg Jan 15 '16 at 23:18

0 Answers0