Mobile app version of vmapp.org
Login or Join
Kevin459

: InDesign, Grep and Syntax Highlighting I have to make an e-book that contains code snippets. I am using GREP to select all code tags (bounded by <> — triangular brackets), and apply a

@Kevin459

Posted in: #AdobeIndesign #CharacterStyles #Grep #IndesignScripting

I have to make an e-book that contains code snippets. I am using GREP to select all code tags (bounded by <> — triangular brackets), and apply a custom style to them.

The RegEx I have developed: regexr.com/39puq
Works fine online.

However, it does not work in InDesign. I've attached an image (see the difference between it and the link above.

The second paragraph contains a set of indentations that InDesign just skips.

Any idea why? Am I missing something?

Thank you.

Later edit:

Following another StackExchange thread, I found this snippet: <.*>

However, it has the same undesired effect. Help.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Kevin459

2 Comments

Sorted by latest first Latest Oldest Best

 

@Jennifer810

Your problem is that the multi-line item isn't one paragraph as far as InDesign is concerned. It's 5 paragraphs.

Replace the paragraph returns with forced line breaks (Shift-Enter) and it will work as expected.

10% popularity Vote Up Vote Down


 

@Gail6891361

Don't try to match generic XML with regexp. It will not work in many cases, use a XML parser instead and export the result. See:


Why it's not possible to use regex to parse HTML/XML: a formal explanation in layman's terms, especially the second answer.


In any case the grep style does not allow matches over paragraph boundaries because its not a multi paragraph parser . You can circumvent this problem tough, by replacing all end of paragraphs with forced line breaks. This causes in design to consider it one line and match better. Now your regexp would work.

Then your regexp could be simplified as:

</?(.|n)*?>


As matching (.|/s|/S) is somewhat redundant as most of /s and /S is included in . although n is NOT so jsut adding that one exception makes testing easier. Regexp engines in general differ in the way they handle multiline stuff so beware problems lie this way.

WARNING: This regexp won't be really robust as it does understand nested <>. So commented code may screw up royally. Use a parser to dump the stuff as RTF, much better approach.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme