Quitter
  • Communauté internationale
    • Langue:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티

GREP to remove runts in a contact listing within a paragraph

Explorateur ,
Jul 28, 2021 Jul 28, 2021

In my job, we create basically a phone book. Each entry is a paragraph, but each field of data is separated by a forced line break. If a company name is too long in the column, it will create a runt/cliff withing the boundary of the beginning of the paragraph to the end of the field of data (the forced line break). Is there a GREP I can run to identify when these happen? Note that I want to identify these, NOT do a change all. 

 

In theory what I want is to search for a single word on a line that has a forced line break at the end, but has no "beginning" other than it being on a second line. 

 

Does that make sense?

SUJETS
Guide pratique
2.0K
Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines

correct answers 1 bonne réponse

Guide , Jul 30, 2021 Jul 30, 2021

Just For Fun!

 

(^/)  The Jedi

 

Capture d’écran 2021-07-30 à 19.09.10.png

 

/*
    _FRIdNGE-0728_LineRunt.jsx
    by FRIdNGE, Michel Allio [30/07/2021]
*/

var myDoc = app.activeDocument;

var myCondition = myDoc.conditions.item("runt");
if (!myCondition.isValid) myCondition = myDoc.conditions.add ({name: "runt", indicatorMethod: ConditionIndicatorMethod.USE_HIGHLIGHT, indicatorColor: [255,186,131]});

var myStories = myDoc.stories,
S = myStories.length,  s;
for ( s = 0; s < S ; s++ ) {
    var myParas = myStories[s].paragraphs,
    P = myP
...
Traduire
Community Expert ,
Jul 28, 2021 Jul 28, 2021

Well, I'm not completely certain that I understand exactly what you're not looking for, but I think that this will find what you are looking for:

\S+\n(?-m)

This will find any non-spaces followed immediately by a forced line break. I wrote this regex to look for non-spaces,  but you may have to use something else, if you have single-word entries that you don't want your regex to find. 

 

I did this by adding "multiline off":

(?-m)

This regex will not find anything other than that single word. If there is a trailing space after the word and before the forced line break, this won't match it. 

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Explorateur ,
Jul 28, 2021 Jul 28, 2021

Think of it more so as: 

 

^p

ABC Welding & Supply^n
Jane Doe^n

etc. etc. 

 

But the column breaks it to look like: 

^p

ABC Welding &
Supply^n
Jane Doe^n

etc. etc. 

 

I want to find a single word (Supply) on it's own line, but has not been forced by a hidden character. Right now I don't know how to find any single word on it's own line. Is there a way to say "New Line" in text not made by a hidden character?

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Community Expert ,
Jul 28, 2021 Jul 28, 2021

This GREP expression should find a single word on a line by itself that is not preceeded by a line break and is followed immediatgely by another line break or a hard return:

(?<!~b)[\u\l]+(~b|$) 

It will not find multiple words nor lines that have punctuation or trailing space, so you need to tell us if that is a possibility.

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Explorateur ,
Jul 29, 2021 Jul 29, 2021

The problem is that when I search within this selection alone, which has the runt I'm looking for. I does find Service, but it also found "Gentry" which is NOT on it's own line. What am I doing wrong? This new expression you've included does not find it either. 

 

Screen Shot 2021-07-29 at 7.46.25 AM.pngScreen Shot 2021-07-29 at 7.46.44 AM.png

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Community Expert ,
Jul 29, 2021 Jul 29, 2021

Sorry.

 

I have to admit I'm a bit rusty with GREP. My query in fact finds the last word before a line break whether it is isolated or not, and thinking about it some more, I'm pretty sure it's not actually possible to find the beginning of a "naturally broken" line using GREP.

 

I think this was a topic of discussion many years back and there might have been a scripting solution suggested at the time.

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Explorateur ,
Jul 29, 2021 Jul 29, 2021

Thank you for the information. Is there an easy way to request this with Adobe?

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Community Expert ,
Jul 29, 2021 Jul 29, 2021

https://www.adobe.com/products/wishform.html

 

Understand that a feature request needs to have some explanation of how it will benefit large numbers of users. It's not entirely clear to me what exactly you want Adobe to do. 

 

I did a quick forum search and came up with these two old threads that might help you:

https://community.adobe.com/t5/indesign/find-a-word-at-the-beginning-of-the-line/m-p/10729176#M16014...

https://community.adobe.com/t5/indesign/finding-replacing-beginning-or-end-of-a-line/m-p/9766856#M93...

 

Not being a scripter myself I can't really help with making changes, but it might be worth trying Jongware's script and seeing if it will work if you input my GREP expression in the prompt. My gut says it probably will not, but you can give it a shot.

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Ambassadeur ,
Jul 29, 2021 Jul 29, 2021

I'm unclear why you're using forced line breaks as I see in your screen shot? Doing so makes formatting your text with character styles much more work than if you'd used conventional paragraph styles. This kind of formatting also precludes you from using InDesign's Apply Next feature, which is a very fast and powerful tool for quickly applying sequential styles to a cascade of text. Unless there's a compelling reason to do so, I almost never use forced line breaks and don't teach their use to my students.

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Explorateur ,
Jul 29, 2021 Jul 29, 2021

This is how my company creates listings. We typically apply character styles using a table at the beginning of our import process. Not every field of data is used when we import these listings, so the apply next feature wouldn't work well. We also need to ensure that all lines in the paragraph are kept together. Also, we need this feature for more than just listings as we also use them in are articles

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Explorateur ,
Jul 29, 2021 Jul 29, 2021

We also tend to use paragraph shading/boxing en masse for a lot of our project which wouldn't work with multiple paragraph styles

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Explorateur ,
Jul 29, 2021 Jul 29, 2021

Also, I am still getting orphans/cliffs even if I converted my styles to a paragraph style. Other than balance ragged lines, it doesn't solve my issue that a single word sometimes ends on a line by itself. If I were able to convince my job to change to paragraph styles, we wouldn't be fixing the problem without a script or GREP being written to find this. My Scripting skills are null. So i'm not sure what I'm even writing when I attempt to solve this issue.

Screen Shot 2021-07-29 at 3.01.48 PM.png

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Ambassadeur ,
Jul 29, 2021 Jul 29, 2021

Hmm. OK. Looks like a convoluted solution to me, but if it works for you so be it.

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Community Expert ,
Jul 29, 2021 Jul 29, 2021

I am a very slow scripter, but I'm about 1/3 of the way through a script that will analyze all paragraphs in a story, find all lines that have only one word, and then Do Something. I'm working this way because I don't think you've ever said what you want that Something to be.

 

But if it's as simple as "how do I prevent runts?" then it's comparatively easy to write a regex find/change query that applies No Break to the last two words before any forced line break, or that inserts a no-break space right before the last word before a forced line break, or that applies No Break to the last n characters before any forced line break. 

 

 

 

 

 

 

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Explorateur ,
Jul 30, 2021 Jul 30, 2021

That is awesome thank you. The something I want to happen is only to find them. The goal is to help proof the layouts we're working in and find the errors easily to make whatever judgement to fix them. So I just need it to find the error. Maybe that will help make the script easier?

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Explorateur ,
Jul 30, 2021 Jul 30, 2021

In All reality, I don't know if a script can do a single find/change find/change like we can with the Find/Replace funtion. But If I can at least identify these runts, that would be most helpful

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Guide ,
Jul 30, 2021 Jul 30, 2021

Just For Fun!

 

(^/)  The Jedi

 

Capture d’écran 2021-07-30 à 19.09.10.png

 

/*
    _FRIdNGE-0728_LineRunt.jsx
    by FRIdNGE, Michel Allio [30/07/2021]
*/

var myDoc = app.activeDocument;

var myCondition = myDoc.conditions.item("runt");
if (!myCondition.isValid) myCondition = myDoc.conditions.add ({name: "runt", indicatorMethod: ConditionIndicatorMethod.USE_HIGHLIGHT, indicatorColor: [255,186,131]});

var myStories = myDoc.stories,
S = myStories.length,  s;
for ( s = 0; s < S ; s++ ) {
    var myParas = myStories[s].paragraphs,
    P = myParas.length,  p;
    for ( p = 0; p < P ; p++ ) {
        var myLines = myParas[p].lines,
        L = myLines.length,  l;
        for ( l = 0; l < L-1 ; l++ ) if ( myLines[l].characters[-1].contents === " " ) myLines[l+1].appliedConditions = [myCondition];
    }
}
Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Explorateur ,
Jul 30, 2021 Jul 30, 2021

THIS WORKS EXACTLY LIKE I NEEDED IT! Thank you SO much! 

 

On a side note, do you have a good resource for me to start learning what this coding means? Or where I should go to learn how to write my own scripts?

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Guide ,
Jul 30, 2021 Jul 30, 2021

Other way based on Grep!

 

/*
    _FRIdNGE-0728B_LineRunt.jsx
    by FRIdNGE, Michel Allio [30/07/2021]
*/

var myDoc = app.activeDocument;

var myCondition = myDoc.conditions.item("runt");
if (!myCondition.isValid) myCondition = myDoc.conditions.add ({name: "runt", indicatorMethod: ConditionIndicatorMethod.USE_HIGHLIGHT, indicatorColor: [255,186,131]});

app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = ".+";

myFound = myDoc.findGrep();
var F = myFound.length,  f;

for ( f = 0; f < F ; f++ ) if ( myFound[f].lines.length == 2 ) myFound[f].lines[1].appliedConditions = [myCondition];

app.findGrepPreferences = null;

 

(^/)

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Explorateur ,
Jul 30, 2021 Jul 30, 2021

Is there a way to go further with a "myWords" and have the word count be 1 on a line?

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Guide ,
Jul 30, 2021 Jul 30, 2021

In the 2nd Script, change this line:

 

for ( f = 0; f < F ; f++ ) if ( myFound[f].lines.length == 2 && myFound[f].lines[1].words.length == 1 ) myFound[f].lines[1].appliedConditions = [myCondition];

 

(^/) 

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Guide ,
Jul 30, 2021 Jul 30, 2021

In the 1rst Script:

 

for ( l = 0; l < L-1 ; l++ ) if ( myLines[l].characters[-1].contents === " " && myLines[l+1].words.length == 1 ) myLines[l+1].appliedConditions = [myCondition];

 

(^/) 

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Débutant dans la communauté ,
Jan 20, 2023 Jan 20, 2023

I love this script that highlights runts. So perfect!

But after going throught the file fixing the runts I want to, I'd like to turn off the highlights but no clue how to do that. I never realized ID doesn't have a highlight text feature. Is there a script we can use that will unhighlight everything?
Thanks so much for you expertise and time 🙂

 

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Débutant dans la communauté ,
Jan 20, 2023 Jan 20, 2023

I should add that I would like to use the 1st script, which works great. I tried the 2nd one but it only found runts in paras that only have 2 lines. It wouldn't find the runts in paras that had more than 2 lines.

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Débutant dans la communauté ,
Jan 27, 2023 Jan 27, 2023
LA PLUS RÉCENTE

Oh! I found it now, just delete runt in the conditional text panel, to remove the highlights

 

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines