Skip to main content
Known Participant
February 3, 2013
Answered

remove carriage return from tagged text

  • February 3, 2013
  • 2 replies
  • 1504 views

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;

    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?

This topic has been closed for replies.
Correct answer Trevor:

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;

with something like

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

Didn't test it but should work.

Don't forget to say ta very much.

Trevor

2 replies

Known Participant
February 3, 2013

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.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.

Trevor:
Legend
February 4, 2013

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

and

var currentParargraph:Paragraph = paragraphs;

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

Known Participant
February 5, 2013

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...

Trevor:
Trevor:Correct answer
Legend
February 3, 2013

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;

with something like

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

Didn't test it but should work.

Don't forget to say ta very much.

Trevor