Remove character at the end of a line of wrapped text
Learn / Forums / General InDesign Topics / Remove character at the end of a line of wrapped text
- This topic has 8 replies, 4 voices, and was last updated 7 years, 10 months ago by Mike Schleman.
-
AuthorPosts
-
-
May 24, 2016 at 9:49 pm #85185Mike SchlemanMember
Hi. Two questions please.
Let’s say that I have a cell in a table that has the following text: 1,3,7,13,20,25,29,32,35,39,55,72,133,136,139,525
Next, assume that the width of the cell causes the text to wrap onto three lines.
Question #1: can you specify the line-break character? I’m sure you can, I just couldn’t find it it. In this example, I want the line to break on the comma. I tried messing with this, the numbers themselves were being broken in the middle at times.
Question #2: with the line breaking on the comma, can I remove the comma (or at least hide it) at the end of a line that is wrapped?
So, if the wrapped text in a cell would look like:
1,3,7,13,20,25,29,
32,35,39,55,72,133,
136,139,525I would like the resulting text to look like:
1,3,7,13,20,25,29
32,35,39,55,72,133
136,139,525Thanks in advance for the help!
-
May 25, 2016 at 1:09 am #85189Peter KahrelParticipant
Question #1: Add a discretionary line break after every comma. That’ll keep the digits together.
Question #2: Not automatically. A Grep style won’t work because you can’t find the end of turn lines (except when you add forced line breaks, which you probably don’t want). But a script can do that.
Create a character style Hide (set just the colour to Paper), then click somewhere in the table and run the script.
(function () { var i, lines, cells; cells = app.selection[0].parent.parent.cells.everyItem().getElements(); for (i = 0; i < cells.length; i++) { cells[i].texts[0].appliedCharacterStyle = app.documents[0].characterStyles[0]; cells[i].texts[0].clearOverrides (OverrideType.CHARACTER_ONLY); lines = cells[i].lines; for (j = 0; j < lines.length; j++) { if (lines[j].characters[-1].contents == SpecialCharacters.DISCRETIONARY_LINE_BREAK) { lines[j].characters[-2].appliedCharacterStyle = 'Hide'; } } } }());
Peter
-
May 25, 2016 at 8:18 am #85207Mike SchlemanMember
Thank you Peter for the quick reply.
Regarding question #1, can discretionary line breaks be imported in XML?
Regarding question #2, I thought this might be the case. In looking at your script, if I’m reading this correctly, you are hiding every comma, not just the comma at the end of a link where a wrap occurred. Am I correct?
-
May 25, 2016 at 9:31 am #85210Peter KahrelParticipant
> can discretionary line breaks be imported in XML?
Probably. Their hex code is 200B, you can use that. Not sure how, though.
> you are hiding every comma, not just the comma at the end of a link where a wrap occurred. Am I correct?
Not really. The script first unhides all commas, then hides the commas at the end of each line. That’s really only needed if you change the width of a column table, because the styles aren’t updated automatically when you resize a column. If you never resize, then lines 5 and 6 can be deleted (the two lines starting with cells[i].texts[0]).
P.
-
May 25, 2016 at 10:43 am #85212Matt IsaacParticipant
Peter,
I am trying to learn/understand coding myself. From what I see, wouldn’t that script apply the ‘Hide’ character style to the last two characters in a line that ends with a discretionary line break; even if the line ended with a discretionary line break following a letter?
ex. This is my sentence(Discretionary Line Break) with a dlb.
If the text needed to be broke at that dlb wouldn’t the text read:
“This is my sentenc
with a dlb.”??
Just trying to understand for myself. -
May 25, 2016 at 11:11 am #85219Ari SingerMember
You’re absolutely right, but Peter didn’t care about that because in this situation he knew there will only be discretionary line breaks after a comma. So he didn’t bother. But in the real world if there was such a case then that line will be written as such:
if ((lines[j].characters[-1].contents == SpecialCharacters.DISCRETIONARY_LINE_BREAK) && (lines[j].characters[-2].contents = ",")) { lines[j].characters[-2].appliedCharacterStyle = 'Hide';
Which basically says: If the last character is a discretionary line break and there is a comma before that, then…
-
May 25, 2016 at 11:36 am #85222Ari SingerMember
Sorry, just noticed a flaw in my code. I wrote a single ‘=’ instead of ‘==’. So here’s the fixed code:
if ((lines[j].characters[-1].contents == SpecialCharacters.DISCRETIONARY_LINE_BREAK) && (lines[j].characters[-2].contents == ",")) {
lines[j].characters[-2].appliedCharacterStyle = 'Hide';
Unfortunately, for whatever reason, I can’t always edit my posts :(
-
-
May 25, 2016 at 11:20 am #85221Peter KahrelParticipant
> wouldn’t that script apply the ‘Hide’ character style to the last two characters
No:
lines[j].characters[-2]
means ‘the one-before-last character in lines[j]’> in a line that ends with a discretionary line break; even if the line ended with a discretionary line break following a letter?
That’s true. But in Mike’s example that wasn’t the case.
P.
-
May 27, 2016 at 8:02 pm #85270Mike SchlemanMember
Thank you everyone’s kind input on this.
-
-
AuthorPosts
- You must be logged in to reply to this topic.