Quantcast
Channel: Adobe Community: Message List - InDesign Scripting
Viewing all articles
Browse latest Browse all 37788

Re: Make hyperlink text actual hyperlinks

$
0
0

Hi,

as you want to use the found link itsself as textsource ... have you thought of calling the command 'convert Urls to hyperlinks in the GUI'¿

The link-tags wouldn't be needed then ...

 

A script could be like this:

 

app.findGrepPreferences = app.changeGrepPreferences = null;
var doc = app.activeDocument;
app.findGrepPreferences.findWhat = '(?<=<link>)[^<link>]+(?=</link>)';
var objs = doc.findGrep();
 l = objs.length; while(l--){     var currTarget  = objs[l];    var lnkDest = doc.hyperlinkURLDestinations.add(currTarget.texts[0].contents);    var lnkSrc = doc.hyperlinkTextSources.add(currTarget);    var lnk = doc.hyperlinks.add(lnkSrc, lnkDest);    /*    var leftIndex = currTarget.index;    var rigthIndex = currTarget.index + objs[l].length;    var pStory = currTarget.parentStory;    pStory.characters.itemByRange(rigthIndex, rigthIndex+6).remove();      pStory.characters.itemByRange(leftIndex-6, leftIndex-1).remove();      */       } 
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = '<link>|</link>';
app.changeGrepPreferences.changeTo = '';
doc.changeGrep();

 

The commented stuff would delete the link-Tags during the repeatloop instead of the actually used second search ...

Didn't test what'll be faster ...


Viewing all articles
Browse latest Browse all 37788

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>