8 Replies Latest reply on Aug 9, 2013 10:30 AM by JoaoCP

    InDesign: Help with Grep Styles (don't work consistently)

    big_smile Level 1

      I found this excellent tutorial which allows GREP styles to fake the functionality of HTML tags.

       

      So  The cat sat on the <b>Mat</b> is displayed in InDesign as:  The cat sat on the Mat.

       

       

      The trouble is that it doesn't work consistently.

       

      Here I have two text items that are display on seperate pages in seperate text boxes. Both have the same paragraph style applied to them (which use the HTML GREP tehcnique)

       

      <b> "Make me Jonathan's birthday card, super duper quick!"</b> adds Ben.

      Holly's magic wand twinkles and the paintbrushes lift up into the air.

      "It works!" cries Holly and Ben.

       

      <b> "Humpy, lumpy, bumpy, make

      King Thistle nice and comfy."</b>

      "Thank you, you can go now

      Nanny Plum," says King Thistle.

       

      The first paragraph works perfectly. The <b> tags are hidden and the bold character style is applied.

      The second paragraph doesn't work. The <b> tags are hidden, but the characters don't turn bold.

       

      What could be causing this?

       

      Here is my GREP code:

       

      Apply HTML Style to Text: (<\/*b>)

      Apply Bold Style to Text: (<b>).+(</b>)

       

      (HTML style is used to hide the HTML characters. Bold Style makes it bold).

       

      Thanks for any help that can be offered    

        • 1. Re: InDesign: Help with Grep Styles (don't work consistently)
          JoaoCP Level 2

          By default, the dot wildcard doesn't match line endings. To override this behavior, prefix your grep pattern with (?s), like this:

           

          (?s)(<b>).+(</b>)

          1 person found this helpful
          • 2. Re: InDesign: Help with Grep Styles (don't work consistently)
            JoaoCP Level 2

            Oh, by the way: your current "Apply Bold Style to Text" pattern may return unexepected results. Take a look at the example below:

             

            • Some words in <b>bold</b> and some other words also in <b>bold</b>.

             

            You should've expected this result:

             

            • Some words in bold and some other words also in bold.

             

            However, due to the fact that your grep pattern matches everything between <b> and </b>, the actual output will be:

             

            • Some words in bold and some other words also in bold.

             

            As you can see, the pattern indeed matches everything between <b> and </b>, but "everything" includes any other </b> it finds in the way!

             

            To avoid this, use the "non-greedy" version of the repeat pattern:  .+?

             

            Using this method, your "Apply X Style to Text" patterns should be like this:

             

            (?s)<b>.+?</b>

             

            The above example tells InDesign to match a <b> and everything through the first </b>, then stop.

             

            (I also removed the parentheses surrounding <b> and </b>, because they're unnecessary.)

            1 person found this helpful
            • 3. Re: InDesign: Help with Grep Styles (don't work consistently)
              big_smile Level 1

              JoaoCP, thank you so much for taking the time to help. I really appreciate it!

               

              I've tried you new code, but it doesn't seem to work. The paragraphs where bold was working still work, but the ones that didn't work before still don't work (although, as before the HTML tags are hidden).

               

              Here is my code:

               

              Apply HTML Style to Text: (<\/*b>)

              Apply Bold Style to Text: (?s)<b>.+?</b>

               

              Here are my paragraphs (same as before)

               

              <b> "Make me Jonathan's birthday card, super duper quick!"</b> adds Ben.

              Holly's magic wand twinkles and the paintbrushes lift up into the air.

              "It works!" cries Holly and Ben.

               

              <b> "Humpy, lumpy, bumpy, make

              King Thistle nice and comfy."</b>

              "Thank you, you can go now

              Nanny Plum," says King Thistle.

               

              Thanks for any help that can be offered!

              • 4. Re: InDesign: Help with Grep Styles (don't work consistently)
                big_smile Level 1

                I have copied and pasted my paragraphs into a  new document and put it here:

                 

                http://olo.uk.com/testdocument.idml

                 

                Thanks for any help, as I am stumpped!!

                • 5. Re: InDesign: Help with Grep Styles (don't work consistently)
                  Joel Cherney Adobe Community Professional & MVP

                  Is there a paragraph return after "make"? You can check by turning on View -> Display Mode -> Normal and then Type -> Show Hidden Characters (not sure about the last one, my phone doesn't have InDesign on it ).

                   

                  GREP styles cannot span multiple paragraphs. So if the opening bold tag is in one paragraph, and the closing tag is in the second paragraph, it'll never work.

                  • 6. Re: InDesign: Help with Grep Styles (don't work consistently)
                    Peter Spier Most Valuable Participant (Moderator)

                    I was just about to post that GREP syles don't seem to understand single-line mode, but Joel did it better.

                     

                    I have a suggestion, though, to improve the look of the hidden html tags: In the character style, first remove the font family name and style (you don't need them, and styles are more versatile the less specific they are for things you aren't changing), then in the advanced character formatting set the horizontal scale to 1% to tighten it up even more. Now get rid of the spaces between the tags and the words they affect.

                    1 person found this helpful
                    • 7. Re: InDesign: Help with Grep Styles (don't work consistently)
                      big_smile Level 1

                      Thanks, that was the problem - it was on multiple lines.

                      • 8. Re: InDesign: Help with Grep Styles (don't work consistently)
                        JoaoCP Level 2

                        Hi, big_smile.

                         

                        I took a look at your document. As others pointed out, grep styles don't span multiple paragraphs.

                         

                        But my examples do work if you use linebreaks instead of paragraph breaks. In fact, when you said (in the first post) that "The second paragraph doesn't work", I assumed that you were using linebreaks, so I showed you a grep pattern that works under this condition.

                         

                        Therefore, if you treat these block of lines as individual paragraphs (using linebreaks instead of paragraph returns), the grep pattern I suggested will work.

                         

                        Hope it helps.