[GastForen Programme Print/Bildbearbeitung Adobe InDesign Script für automatische Webverlinkung in Indesign?

  • Suche
  • Hilfe
  • Lesezeichen
  • Benutzerliste
Print/Bildbearbeitung - Photos, Layout, Design
Themen
Beiträge
Moderatoren
Letzter Beitrag

Script für automatische Webverlinkung in Indesign?

der-markus
Beiträge gesamt:

9. Feb 2007, 15:47
Beitrag # 1 von 6
Bewertung:
(1106 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo,

folgendes Problem: In meinem Indesign-Dokument gibt es jede Menge Internetadressen, die (momentan noch) manuell mit einem Hyperlink versehen werden müssen. Gibt es eine Möglichkeit (bspw. Skript) um das ganze automatisch generieren zu lassen?

Mein Pfad beginnt allerdings nicht mit "http://www....." sondern direkt mit "www."
X

Script für automatische Webverlinkung in Indesign?

Martin Fischer
  
Beiträge gesamt: 12732

9. Feb 2007, 16:21
Beitrag # 2 von 6
Beitrag ID: #275537
Bewertung:
(1093 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Unter http://www.adobeforums.com/...6gHrqYyX@.3bc1cd8b/8 hat Olav Kvern ein Skirpt zur Erzeugung von Weblinks veröffentlicht.

Es setzt allerdings ein "http://" vor der Web-Adresse voraus.


Code
//MakeHyperlinks_CS2.jsx   
//An InDesign CS2 JavaScript
//
//Finds a string in text and creates a hyperlink based on the
//contents of the string. This script employs a hybrid approach to
//finding and changing text, using both JavaScript regular expressions
//and InDesign's search method.
//
main();
function main(){
if(app.documents.length != 0){
if(app.documents.item(0).stories.length != 0){
//Construct regular expression to find hyperlink sources.
//The following RegExp should find all URLs in text.
var myRegExp = /\b(https?|ftp|file):\/\/[-A-Za-z0-9+&@#\/%?=~_|!:,.;]*[-A-Za-z0-9+&@#\/%=~_|]/gi;
var myURLPrefix = "";
var myURLSuffix = ""
mySearchStories(myRegExp, myURLPrefix, myURLSuffix);
//Next, do it again to find the GAO-specific documents.
myRegExp = /GAO(-|\/)[\d]*-[\d]*/gi;
myURLPrefix = "http:\/\/www.gao.gov\/cgi-bin\/getrpt?";
myURLSuffix = ".html"
mySearchStories(myRegExp, myURLPrefix, myURLSuffix);
//Finally, catch the email addresses and convert to mailto links.
myRegExp = /\b[A-Za-z0-9._%-]+@(?:[A-Za-z0-9-]+\.)+[A-Za-z]{2,4}\b/gi
myURLPrefix = "mailto:";
myURLSuffix = ""
mySearchStories(myRegExp, myURLPrefix, myURLSuffix);
}
else{
alert("The current document does not contain any text.");
}
}
else{
alert("Please open a document and try again.");
}
alert("Done!");
}
function mySearchStories(myRegExp, myURLPrefix, myURLSuffix){
var myStory, myStoryText, myFoundItems, myFoundStrings, myHyperlinkDestination, myFootnoteCounter;
var myStart, myEnd, myFootnote, myStringCounter, myFoundItem, myTableCounter, myCellCounter, myTable, myCell;
var myHyperlinkTextSource, myTextCounter, myStringCounter;
var myFoundStrings = new Array;
var myDocument = app.documents.item(0);
var myHyperlinkStyle = myDocument.characterStyles.item("hyperlink text");
for(var myCounter = 0; myCounter < myDocument.stories.length; myCounter ++){
//Get the text of the story as a string.
myStory = myDocument.stories.item(myCounter);
if(myStory.characters.length > 1){
myStoryText = myStory.contents;
//If the story contains only a special character (such as an auto page number marker),
//the following will fail, so use try...catch to avoid the problem.
try{
if(myStoryText.match(myRegExp)!=null){
myFoundStrings = myFoundStrings.concat(myStoryText.match(myRegExp));
}
}
catch (myError){}
}
//The text of tables in the story will not appear in myStory.contents, so
//we need to search the text of each story. There's always the possibility that
//the cells contain tables of their own, but this script won't check for that possibility.
if(myStory.tables.length != 0){
for(myTableCounter = 0; myTableCounter < myStory.tables.length; myTableCounter++){
myTable = myStory.tables.item(myTableCounter);
for(myCellCounter = 0; myCellCounter < myTable.cells.length; myCellCounter++){
myCell = myTable.cells.item(myCellCounter);
//Does the cell contain any text? If it does, the length of the
//insertion points collection will be greater than 1.
if(myCell.insertionPoints.length > 1){
myCellText = myCell.texts.item(0).contents;
if(myCellText.match(myRegExp)!= null){
myFoundStrings = myFoundStrings.concat(myCell.texts.item(0).contents.match(myRegExp));
}
}
}
}
}
}
if(myFoundStrings.length > 0){
myFoundStrings = myRemoveDuplicates(myFoundStrings);
//Search through the sorted strings in reverse order--that way, you'll catch the longer URLs
//before the base URLs (e.g., http://www.adobe.com *after* http://www.adobe.com/products).
for(myStringCounter = myFoundStrings.length-1; myStringCounter >= 0; myStringCounter--){
myClearFindChange();
myFoundItems = myDocument.search(myFoundStrings[myStringCounter]);
if(myFoundItems.length != 0){
myHyperlinkDestination = myMakeURLHyperlinkDestination(myURLPrefix + myFoundStrings[myStringCounter] + myURLSuffix);
for(myTextCounter = 0; myTextCounter < myFoundItems.length; myTextCounter++){
myFoundItem = myFoundItems[myTextCounter];
myMakeHyperlink(myFoundItem, myHyperlinkDestination, myHyperlinkStyle);
}
}
myClearFindChange();
}
}
myFoundString = new Array;
//Handle the footnotes here.
//Iterate through the stories again.
for(var myCounter = 0; myCounter < myDocument.stories.length; myCounter ++){
myStory = myDocument.stories.item(myCounter);
if(myStory.footnotes.length > 0){
for(myFootnoteCounter = 0; myFootnoteCounter < myStory.footnotes.length; myFootnoteCounter++){
myFootnote = myStory.footnotes.item(myFootnoteCounter);
myStoryText = myFootnote.texts.item(0).contents;
try{
if(myStoryText.match(myRegExp)!=null){
myFoundStrings = myStoryText.match(myRegExp);
//Found at least one matching string in the footnote, so use
//itemByRange to construct a text object, then use that object to
//create a hyperlink text source.
for(myStringCounter = 0; myStringCounter < myFoundStrings.length; myStringCounter++){
myFoundString = myFoundStrings[myStringCounter];
myStart = myStoryText.indexOf(myFoundString);
myEnd = myStart + myFoundString.length-1;
myFoundItem = myFootnote.texts.itemByRange(myFootnote.characters.item(myStart), myFootnote.characters.item(myEnd));
myHyperlinkDestination = myMakeURLHyperlinkDestination(myURLPrefix + myFoundString + myURLSuffix);
myMakeHyperlink(myFoundItem, myHyperlinkDestination, myHyperlinkStyle);
}
}
}
catch (myError){}
}
}
}
}
function myMakeHyperlink(myFoundItem, myHyperlinkDestination, myHyperlinkStyle){
var myDocument = app.documents.item(0);
try{
var myHyperlinkTextSource = myDocument.hyperlinkTextSources.add(myFoundItem);
var myHyperlink = myDocument.hyperlinks.add(myHyperlinkTextSource, myHyperlinkDestination);
//Hyperlink and text formatting attributes.
myFoundItem.applyStyle(myHyperlinkStyle, false);
myHyperlink.visible = false;
}
catch(myError){}
}
function myMakeURLHyperlinkDestination(myURL){
var myDocument = app.documents.item(0);
//If the hyperlink destination already exists, use it;
//if it doesn't, then create it.
try{
var myHyperlinkDestination = myDocument.hyperlinkURLDestinations.item(myURL);
myHyperlinkDestination.name;
}
catch(myError){
myHyperlinkDestination = myDocument.hyperlinkURLDestinations.add(myURL);
}
myHyperlinkDestination.name = myURL;
//Set other hyperlink properties here, if necessary.
return myHyperlinkDestination;
}
function myRemoveDuplicates(myArray){
//Semi-clever method of removing duplicate array items; much faster
//than comparing every item to every other item!
var myNewArray = new Array;
myArray = myArray.sort();
myNewArray.push(myArray[0]);
if(myArray.length > 1){
for(var myCounter = 1; myCounter < myArray.length; myCounter ++){
if(myArray[myCounter] != myNewArray[myNewArray.length -1]){
myNewArray.push(myArray[myCounter]);
}
}
}
return myNewArray;
}
function myClearFindChange(){
app.findPreferences = NothingEnum.nothing;
app.findPreferences = NothingEnum.nothing;
}



als Antwort auf: [#275529]
(Dieser Beitrag wurde von Martin Fischer am 11. Feb 2007, 20:53 geändert)

Script für automatische Webverlinkung in Indesign?

Martin Fischer
  
Beiträge gesamt: 12732

11. Feb 2007, 21:05
Beitrag # 3 von 6
Beitrag ID: #275688
Bewertung:
(1054 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo Markus,

um Hyperlinks, die nicht mit "http://" oder "ftp://" beginnen, sondern mit "www.", zu markieren ersetze im obigen Skript die Zeile 15 (var myRegExp = ...) durch folgende Zeile
Code
var myRegExp = /\bwww\.[-A-Za-z0-9+&@#\/%?=~_|!:,.;]*[-A-Za-z0-9+&@#\/%=~_|]/gi; 

Ferner kannst Du in der Zeile darunter (var myURLPrefix = "";) bei Bedarf den URLPrefix ergänzen:

Code
var myURLPrefix = "http://"; 



als Antwort auf: [#275529]

Script für automatische Webverlinkung in Indesign?

der-markus
Beiträge gesamt:

12. Feb 2007, 08:37
Beitrag # 4 von 6
Beitrag ID: #275713
Bewertung:
(1040 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Guten Morgen Martin,

wow. Vielen Dank für deine Hilfe!


als Antwort auf: [#275688]

Script für automatische Webverlinkung in Indesign?

der-markus
Beiträge gesamt:

12. Feb 2007, 08:39
Beitrag # 5 von 6
Beitrag ID: #275714
Bewertung:
(1039 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo Martin,

noch eine Frage: Wie kann/muss ich denn dieses Script einbinden? Kannst du mir bitte dafür noch einen Tipp geben?


als Antwort auf: [#275688]

Script für automatische Webverlinkung in Indesign?

Martin Fischer
  
Beiträge gesamt: 12732

12. Feb 2007, 08:53
Beitrag # 6 von 6
Beitrag ID: #275717
Bewertung:
(1036 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo Markus,

oben unter dem Kasten für Einstellungen | Mitteilungen | Suche | Benutzerliste | FAQ | Mitgliedschaft | Ausloggen findest Du einen Link auf Hilfsmittel und Anleitungen, die im InDesign Forum diskutiert wurden.

Und dort findest Du neben einer Übersicht zu veröffentlichten Skripten auch eine Anleitung zum Sichern von Skripten: http://www.hilfdirselbst.org/...rn&read_group=17


als Antwort auf: [#275714]
X