Skip to main content
Participant
June 13, 2023
Answered

InDesign GREP Help Two...

  • June 13, 2023
  • 4 replies
  • 422 views

Hello again,

 

Is there a way in a paragraph style (via GREP?) to insert a character style to any text that receives a hyperlink?

 

Thanks in advance.

 

J.

This topic has been closed for replies.
Correct answer Peter Kahrel

Is there a way to apply a character style automatically depending on what type of hyperlink it is?

 

You'd need a script for that. Which type of hyperink do you want the character style applied to?

4 replies

Peter Kahrel
Community Expert
Community Expert
June 13, 2023

If you want to apply the character style to all link sources that are not page items, it's easy:

cstyle = app.documents[0].characterStyles.item ('myStyle');
sources = app.documents[0].hyperlinkTextSources.everyItem().getElements();
for (i = sources.length-1; i >= 0; i--) {
  s[i].appliedCharacterStyle = cstyle;
}

because it targets all hyperlink text sources. But if it should be restricted to e.g. URL sources, it gets more complicated.

Barb Binder
Community Expert
Community Expert
June 13, 2023

LOL Peter: you beat me by 7 seconds! 😂

~Barb at Rocky Mountain Training
Barb Binder
Community Expert
Community Expert
June 13, 2023

Hi @JonathanJacqu28834810rfuu:

 

InDesign can do that for you without GREP as you add your URLs.

 

~Barb

~Barb at Rocky Mountain Training
Peter Kahrel
Community Expert
Community Expert
June 13, 2023

You don't need any Grep. When you create a hyperlink you can set a character style in the interface: 

And when you create a hyperlink in a script, you can apply a character style when you create the hyperlink source.

 

 

Participant
June 13, 2023

Right, maybe I should rephrase then, sorry. I have paragraphs that contain many links, some in-page hyperlinks, some external url hyperlinks. Is there a way to apply a character style automatically depending on what type ofhyperlink it is?

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
June 13, 2023

Is there a way to apply a character style automatically depending on what type of hyperlink it is?

 

You'd need a script for that. Which type of hyperink do you want the character style applied to?