5 Replies Latest reply on Oct 29, 2012 8:20 PM by Angusdog

    Creating hyperlinks from structured strings

    EmondMontgomery

      My Word file has a lot of embedded links (URLs), but Word links don't import into InDesign. So I've unpacked Word links in a structured way, with the text of the link and the underlying URL shown like this:

       

      Click on {link}{link-text}www.someurl.com{/link-text}{link-url}http://www.someurl.com/{/link-url}{/link} to learn more.

       

      In InDesign, I want to run a search and replace that will rebuild all such strings as hyperlinks:

       

      Click on www.someurl.com to learn more.

       

      Is this possible?

        • 1. Re: Creating hyperlinks from structured strings
          luis_mendes

          Hi Emond,

           

          You should be able to use a find/change to remove the text around the URL and then use the "Convert URLs to Hyperlinks" function from the Hyperlinks panel to create actual links from the text URLs.

           

          -Luis

          • 2. Re: Creating hyperlinks from structured strings
            EmondMontgomery Level 1

            My example wasn't great -- it didn't make my goal very clear. The text between the {link-text} "tags" is likely to be regular running text that has a link applied to it. The URL between the {link-url} "tags" is the hyperlink URL. Perhaps this example is clearer:

             

            Read the {link}{link-text}interview{/link-text}{link-url}http://www.someurl.com/{/link-url}{/link} to learn more.

             

            would become

             

            Read the interview to learn more.

             

            A script that does this would involve grep, hyperlinking, and something else (an array? a while statement?). Any hints, including tips on ordering steps within the script, would be welcome.

            • 3. Re: Creating hyperlinks from structured strings
              MatthewMariani Level 1

              Hi EmondMontgomery,

               

              I don't understand why Web links in Word would not import into InDesign. They typically do. In any case this might work:

               

              //Assuming: Read the {link}{link-text}interview{/link-text}{link-url}http://www.someurl.com/{/link-url}{/link} to learn more.
              
              
              if( !(app.selection[0] instanceof InsertionPoint) ) {alert("First, target a story by inserting a blinking cursor."); exit(); }
              var found = [], item, sourceRslts = [], urlRslts = [], i, src, dest, d = app.documents[0], stry = app.selection[0].parentStory;
              clearFCPs();
              app.findGrepPreferences.findWhat = "\\{link\\}\\{link\\-text\\}(.+?)\\{\\/link\\-url\\}\\{\\/link\\}";
              found = stry.findGrep(true);
              clearFCPs();
              
              
              for ( i = 0; i < found.length; i++ ) {
                  app.findGrepPreferences.findWhat = "(?<=\\{link\\-text\\})(.+?)(?=\\{\\/link\\-text\\})";
                  sourceRslts = found[i].findGrep();
                  app.findGrepPreferences.findWhat = "(?<=\\{link\\-url\\})(.+?)(?=\\{\\/link\\-url\\})";
                  urlRslts = found[i].findGrep();
                  try{
                      src = d.hyperlinkTextSources.add( sourceRslts[0] );
                      dest = d.hyperlinkURLDestinations.add( urlRslts[0].contents.toString(), {hidden:true} ); 
                      d.hyperlinks.add( src, dest );
                  } catch (e) {}
              }
              
              
              clearFCPs();
              app.changeGrepPreferences.changeTo = "";
              app.findGrepPreferences.findWhat = "\\{link\\}\\{link\\-text\\}";
              stry.changeGrep();
              app.findGrepPreferences.findWhat = "\\{\\/link\\}";
              stry.changeGrep();
              app.findGrepPreferences.findWhat = "\\{\\/link\\-text\\}";
              stry.changeGrep();
              app.findGrepPreferences.findWhat = "\\{link\\-url\\}(.+?)\\{\\/link\\-url\\}";
              stry.changeGrep();
              clearFCPs();
              
              
              function clearFCPs() {
                        app.findChangeTextOptions = app.findChangeGrepOptions = NothingEnum.NOTHING;
                        app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
                        app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
              }
              
              
              • 4. Re: Creating hyperlinks from structured strings
                EmondMontgomery Level 1

                Matthew:

                 

                Cool -- great -- works like a charm. I should mention that I import tagged text into InDesign, not straight Word files -- hence the links not working on import.

                 

                Jim

                Emond Montgomery

                • 5. Re: Creating hyperlinks from structured strings
                  Angusdog Level 1

                  Fantastic! This is exactly what I need to meet a client's request (Relates to http://forums.adobe.com/message/4785096#4785096).

                   

                  I was able to understand what your script did, work out what my script needed to do and adapt the script.

                   

                  Thank you so much for this assistance.

                   

                  Cheers,

                   

                  Simon.