Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

orphan cross references prevent tagging a document

Return to Member Forum

  • Author
    Posts
    • #114221

      Greetings,

      Sometimes when trying to tag a document, I receive an error mentioning the tagging is impossible due to partial selection of a hyperlink in the text. (which is not the case, I.e. I didn’t partially selected a hyperlink)

      This happens while the cross-reference panel is empty. (but looking into story editor, I can see the cross reference hidden markers.)

      My solution for the time being to this is either:

      Going to story editor, and manually finding and removing these orphan cross-references.

      Or using the following script to remove all the cross references and links:

      var activeDocument = app.activeDocument;

      app.activeDocument.hyperlinkTextDestinations.everyItem().remove();

      app.activeDocument.hyperlinkTextSources.everyItem().remove();

      app.activeDocument.hyperlinks.everyItem().remove();

      Now, is there a more elegant way to find and remove these orphan cross references?

      Also, in case of the answer being negative, is there a way to only select only cross references and not all the links in the code? Because this way I lose all my hyperlinks and bookmarks and I have to redefine them from scratch.

      Thanks,
      Kasra

    • #14338583

      I have a similar problem with unused (hidden) cross references imported from Word document.
      I end up with this two scripts:
      First removes unused CR all at once, and second which show position of CR and then ask you if you want to delete one or proceed to next one

      // —- First One —-

      Array.prototype.exists = function(search){
      for (var i=0; i<this.length; i++)
      if (this[i] == search) return true;
      return false;
      }

      var allUsedSources = getHyperlinksUsedSources(); // ALL hyperlink sources
      var allCRSources = app.activeDocument.crossReferenceSources.everyItem().getElements(); //All Cros Reference Sources
      var counter = 0;

      // Check if Cros Reference Source is used
      for (var i = allCRSources.length-1;i >= 0; i–){
      if (!allUsedSources.exists(allCRSources[i])){
      allCRSources[i].remove();
      counter++;
      }
      }

      alert (“Deleted ” + counter + ” unused Cross reference sources”);

      function getHyperlinksUsedSources(){
      return app.activeDocument.hyperlinks.everyItem().source;
      }

      // — END —

      //— Second One —-

      Array.prototype.exists = function(search){
      for (var i=0; i<this.length; i++)
      if (this[i] == search) return true;
      return false;
      }

      var allUsedSources = getHyperlinksUsedSources();
      var allCRSources = app.activeDocument.crossReferenceSources.everyItem().getElements();
      var counter = 0;

      for (var i = allCRSources.length-1;i >= 0; i–){
      var myBoolean = allUsedSources.exists(allCRSources[i]);
      if (!allUsedSources.exists(allCRSources[i])){
      allCRSources[i].showSource();
      if (confirm (“Unused Cross reference source text:”+””+allCRSources[i].sourceText.contents + “”+””+”Delete Cross reference?”)){
      allCRSources[i].remove();
      counter++;
      };
      if (!confirm (“Continue?”)){
      exit();
      }
      }
      }

      alert (“Deleted ” + counter + ” unused Cross reference sources”);

      function getHyperlinksUsedSources(){
      return app.activeDocument.hyperlinks.everyItem().source;
      }

      // — END —

Viewing 1 reply thread
  • The forum ‘EPUB and eBook’ is closed to new topics and replies.
Forum Ads