• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Index page range script issue InDesign

Explorer ,
Dec 16, 2024 Dec 16, 2024

Copy link to clipboard

Copied

I have a script for generating page ranges for an index document in InDesign. While the script executes successfully and creates the page ranges, there is an issue with hyperlinks. For example, if the input is 10, 29, 30, 31, 32, 33, 34, the script converts it to⁣.10, 29-34 However, after the hyphen, the first digit (3 in this case) does not retain its hyperlink, while the last digit (4) does. I have verified this issue both in InDesign and in the ePub output.

Below is my script. If anyone can assist in resolving this, it would be greatly appreciated.

 

 

 if (app.selection.length > 0 && app.selection[0].hasOwnProperty ('baseline')) 
{ 
    var s = app.selection[0].parentStory;   
    app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;   
       
    app.findGrepPreferences.findWhat = '\\d+, ([\\d+, ])+';   
    var r = s.findGrep();   
    for ( aLine = r.length-1; aLine >= 0; aLine-- )   
        r[aLine].contents= checkOneLine ( r[aLine].contents );   
} 
else 
        alert('Achtung!\nBitte einen Textabschnitt auswählen.');     
 
   
function checkOneLine ( aString )   
{   
    var a = aString.split( ', ');   
    for ( var i = 0; i < aString.length-1; i++ )   
    {   
        var k = i +1;   
        while ( k < aString.length && a[k] == Number( a[k-1] ) + 1)   
        {   
            k++;   
        }   
        if ( Number(a[k-1]) >  Number( a[i] ) )   
        {   
            a[i] = a[i] + '–' + a[k-1];   
            a.splice( i+1, k-1-i );   
        }   
    }   
    return  a.join( ', ');   
}   

 

 

 

Shanpub_0-1734356027875.png

 

TOPICS
Bug , EPUB , Scripting , UXP Scripting

Views

75

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 16, 2024 Dec 16, 2024

Copy link to clipboard

Copied

The script rearranges page numbers but does nothing to the hyperlink text sources (those applied to page numbers). The best would be to remove the text sources from all page numbers of a topic in which some page numbers were ranged and create new hyperlinks. That should be pretty staightforward.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 16, 2024 Dec 16, 2024

Copy link to clipboard

Copied

LATEST

@Shanpub 

 

Because you are modifying text contents - not text objects.

 

A different solution to what @Peter Kahrel suggested:

 

After you get your find grep search result - you would've to iterate though all found elements, check if they belong to the same paragraph, then process them - by removing ones in between.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines