3

Long story short, I regularly paste batches of hyperlinks into Google Docs. When they're copied, they're unlinked and purely raw text. When pasting it into Google Docs however, those links (understandably) don't come up as links, and I have to manually link each one.

Is there a short way for Google Docs to automatically change all "hyperlink-looking" text to hyperlinks?

EDIT: Here's the type of things I'm copy-pasting into Google Docs every week:

text
text
text
link

text
text
text
link

etc. (x20)

I already have http:// in front of each link, but since I'm pasting the whole block into Google Docs, it doesn't automatically convert. I'm looking for a way to highlight the whole document, press a button, and change all "link-eligible" text into links.

1

Google Docs will automatically create the link for you; just press ENTER after typing (or copying) the link.

enter image description here

Note: This will only work if you include the protocol (i.e. http:// or https://) or www at the beginning of the link. For example, these links will auto-create:

www.test.com
http://www.test.com

but this one won't:

yahoo.com
  • Thanks for the reply. Unfortunately, that's not something that'll help my situation. To give an example, here's the type of text that I'm copy-pasting into Google Docs every week: text text text link text text text link etc. (x20) I already have the http:// in front of each link - but what I don't want is to have to press Enter or Space 20+ times manually to "activate" that link. – Google fan Mar 2 '18 at 5:21
  • 1
    @Googlefan Ah, Google Docs can't natively do that. You could find an add-on to make the process easier (like Text2Link4Docs) or you could write a script to look through the document after you paste and convert anything starting with "http" into a link. – freginold Mar 2 '18 at 11:36
  • @Googlefan if you have many links that you want to make clickable do this: 1) copy all those links into notepad, 2) change the first link by removing "http" from it 3) copy all links from notepad into the spreadsheet again 4) fix first link. – niaher Mar 21 at 6:30
0

the pattern matching for identifying a link is very basic but this should get you started. It will add a menu to your doc that will look at all highlighted text and make links where it should. (past into script editor, save the script. reload the doc)

the major part of this was modified from this example: https://developers.google.com/apps-script/reference/document/range

function onOpen(e) {
   DocumentApp.getUi()
       .createMenu('My Menu')
       .addItem('make links', 'test')
       .addToUi();
 }


function test(){
var selection = DocumentApp.getActiveDocument().getSelection();
 if (selection) {
   var elements = selection.getRangeElements();
   for (var i = 0; i < elements.length; i++) {
     var element = elements[i];

     // Only modify elements that can be edited as text; skip images and other non-text elements.
     if (element.getElement().editAsText) {
       var text = element.getElement().editAsText();

       if (text.findText("http")){
        text.setLinkUrl(text.getText() )
       }
     }
   }
 }
}
  • by basic i mean it will only work with the example you gave with each url on it's own line starting with http or https If there is a text element with http somewhere in the middle it will make the whole text element into a (mis formatted) link I do not have the regex experience to set up some thing more robust. – Jared Pinkham Apr 2 '18 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.