5 Replies Latest reply on Feb 5, 2013 5:06 AM by Trevorׅ

    remove carriage return from tagged text

    vincent 1982 Level 1

      Hello,

       

      I'm trying to tag some items but i'm having some difficulties. I want to tag all paragraphs in a textframe.

      I'm doing it as following and thats working like its supposed to:

       

      var paragraphs:Array = indesignTools.getParagraphsForTextFrame(currentTextframe.id);
      
      for (var j:uint = 0 ; j < paragraphs.length ; j++) {
          var currentParargraph:Paragraph = paragraphs[j];
          if (currentParargraph.isValid) {
              InDesign.app.activeDocument.xmlElements.add("section", currentParagraph);
          }
      }
      

       

      Now the problem i'm having is that, if the paragraph has a carriage return at the end, then that carriage return shouldnt get tagged,

      so i should end up with a tagged paragraph, NOT including the last carriage return.

      How would i have to modify my code so i can tag all paragraphs without the last carriage return?

        • 1. Re: remove carriage return from tagged text
          Trevorׅ Adobe Community Professional

          Still waiting for some comment of thanks or a helpful on the post about retrieving properties of a "none" character style but anyway....

           

          Why don't you just replace

          var currentParargraph:Paragraph = paragraphs[j];

          with something like

          var currentParargraph:Paragraph = paragraphs[j].characters.itemByRange(0,-2)

           

          Didn't test it but should work.

           

          Don't forget to say ta very much.

           

          Trevor

          • 2. Re: remove carriage return from tagged text
            vincent 1982 Level 1

            First of all i should apologize, i was not aware of this, i have marked your answer, as did i do with this.

             

            Unfortunatly i had to remove the assignment to the paragraph thou.

             

            Had to do it like this:

             

            var currentParargraph = paragraphs[j].characters.itemByRange(0,-2);
            

             

             

            very annoying, since AS3.0 is strongly typed so i wish i could add a type to it.

             

            Did a check and its actually of type CSHostObject (which is the top level element if i'm not mistaken), and i couldnt give it this type neither because then its struggling with the isValid property.

             

            so thats a bit of a shame, but it is working so i thank you for this.

             

            And if anyone has an answer why it is behaving this way then i would love to hear it.

            • 3. Re: remove carriage return from tagged text
              Trevorׅ Adobe Community Professional

              Hi Vincent

               

              Thanks for the mark ups.

               

              I have been writing a flash application in AS2, to say the least I lack experience in any actionscript but have a interest in learning it up a bit for indesign scripts.  I know this is not the correct forum but as you brought it up...

               

              1) What is the difference between

              var currentParargraph = paragraphs[j]

              and

              var currentParargraph:Paragraph = paragraphs[j];

               

              What is the benefit of giving the Paragraph assignment? (this is a general question of what is the benefit of giving any assignment, i.e. String, Number etc.

               

              In some languages one must give assignment but in the limited experience of AS that I have, things seem to work fine without them.

               

              2) I just posted a discussion on the comparative speeds of AS and JS and including as script to test in both environments,  If you can check it out I'd appreciate it.

              see here.

               

               

              Thanks

               

              Trevor

              • 4. Re: remove carriage return from tagged text
                vincent 1982 Level 1

                There is no difference really, but actionscript is a strongly typed language so it's really just good habbit, and i guess it's an advantage for debugging etc...