Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
10

InDesign GREP Help Two...

Community Beginner ,
Jun 13, 2023 Jun 13, 2023

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.

TOPICS
Scripting
418
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Jun 13, 2023 Jun 13, 2023

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

PeterKahrel_0-1686668366018.png

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

 

 

Translate
Community Expert , Jun 13, 2023 Jun 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?

Translate
Community Expert ,
Jun 13, 2023 Jun 13, 2023

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

PeterKahrel_0-1686668366018.png

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

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 13, 2023 Jun 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 13, 2023 Jun 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 13, 2023 Jun 13, 2023

Hi @JonathanJacqu28834810rfuu:

 

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

2023-06-13_08-59-39.png

 

~Barb

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 13, 2023 Jun 13, 2023

LOL Peter: you beat me by 7 seconds! 😂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 13, 2023 Jun 13, 2023
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines