6 Replies Latest reply on Jun 3, 2015 8:17 AM by Willam van Weelden

    Extendscript / Token

    Will1234

      When I delete a token how can I find out later in the code, that I already deleted it - before I save!

      There exists a Token.delete() function but e.g. no Token.isDeleted().

        • 1. Re: Extendscript / Token
          Peter Grainge Adobe Community Professional (Moderator)

          I suspect your question is not related to Adobe's RoboHelp product and that you have asked in the wrong forum.

           


          See www.grainge.org for RoboHelp and Authoring tips

           

           

          @petergrainge

          • 2. Re: Extendscript / Token
            Will1234 Level 1

            No. Again I am in the right forum. The question is targetting ExtendScript in RoboHelp.

            • 3. Re: Extendscript / Token
              Peter Grainge Adobe Community Professional (Moderator)

              Apologies. I read the content and not the title.

               


              See www.grainge.org for RoboHelp and Authoring tips

               

               

              @petergrainge

              • 4. Re: Extendscript / Token
                Willam van Weelden Adobe Community Professional & MVP

                What is your workflow? Do you have a piece of code that is giving you problems?

                 

                I always assumed that if you delete a token, it will not be available anymore in the TokenManager. The following works fine in my project:

                 

                while(typeof(token)!="undefined")

                  {

                  if(token.isTag(startTag) && token.getText() == Content) {//We're in a H3 so let's get all content

                  var warningtext = "";

                  var tokensToDelete = [];

                 

                  var done = false;

                  var tmpToken = token;

                  while(done === false)

                  {

                  if(tmpToken.isTag("p")) {

                  warningtext = tmpToken.getText(true);

                  tokensToDelete.push(tmpToken);

                  }

                  else if(tmpToken.isTag("/p"))//Done!

                  {

                  tokensToDelete.push(tmpToken);

                  done = true;

                  }

                  else

                  {

                  tokensToDelete.push(tmpToken);

                  }

                 

                  tmpToken = tmpToken.next;

                  }

                 

                  token.insertText('<p class="letopkop">'+Content+'</p><p class="letopteskt">'+warningtext+'</p>', true);

                 

                  for(var i=0; i<tokensToDelete.length;i++) {

                  tokensToDelete[i].delete();

                  }

                 

                  saveme = true;

                 

                  }

                 

                  //Next token

                  token = token.next;

                • 5. Re: Extendscript / Token
                  Will1234 Level 1

                  I want to cover following situation:

                   

                    token.delete();

                    token = token.previous.next;

                   

                  The 2nd line should not return the already deleted item or there should exist an "isDeleted()" function which tells me that I already deleted it.

                  • 6. Re: Extendscript / Token
                    Willam van Weelden Adobe Community Professional & MVP

                    Just tried and indeed, if you delete a token it is still there. There is no property or method available to check whether the token is deleted. Please consider leaving a feature request for this to be added: Adobe - Feature Request/Bug Report Form

                     

                    I have tried if there is an easy workaround, but there is no simple workaround for writing your own deletetion option either. If you store the token, you can't simply check other tokens against it. So this is an oversight. Perhaps you can work around this by changing the behaviour of your script to not pass the same token twice. (Or save the file and load it up in the tokenmanager again for a second pass. Far from ideal, but it may help.)