Copy link to clipboard
Copied
I have a character style "nocolor" that I would like to apply to commas that fall at the end of a line, in the middle of a description (client does not like commas at the end of lines, but when copy is reflowed, we have to remember to add the commas back in). Is there a GREP expression that will capture the comma at the end of a line (not paragraph) and apply the character style to it? (in attached example, the comma after "sugar".
Copy link to clipboard
Copied
There's no GREP expression to match the end of a line of text in InDesign, only to match the end of a paragraph. You'll need a script for that. That script can undo undo any existing instances of the hiding character style before applying the style (again).
Then select a text frame or click somewhere in the text. The script targets the selected story only.
style = app.activeDocument.characterStyles.item ('nocolor');
story = app.selection[0].parentStory;
// Remove any existing instances of the style in the selected story
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = ',';
app.findGrepPreferences.appliedCharacterStyle = style;
app.changeGrepPreferences.appliedCharacterStyle = app.activeDocument.characterStyles[0];
story.changeGrep();
// Apply the style to line-final commas
ch = story.lines.everyItem().characters[-2].getElements();
for (i = ch.length-2; i >= 0; i--) {
if (ch[i].contents === ',') {
ch[i].appliedCharacterStyle = style;
}
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now