2 Replies Latest reply on Sep 21, 2012 4:31 PM by Marc Autret

    Remove the line-ender but keep the note

    RobertKyle Level 2

      Somewhere around here I borrowed a nifty findGrep snippet that removes empty paragraphs from the beginning and end of a story. Unfortunately, it doesn't catch the paragraph that contains only a note. This, too, prints as an empty line.

       

      The best idea I can come up with is to test the first paragraph to see if it contains a note && then check to see if .length == 2. Then I'd delete the line-ender.

       

      Anyone know a better way?

        • 1. Re: Remove the line-ender but keep the note
          RobertKyle Level 2

          Having failed to attract the attention of any Great Scripting Minds, I plowed ahead on my own and came up with this:

           

           

          var myParentStory = app.selection[0].parentStory;

          //check top of story for paragraphs containing only notes

          var myFirstGraf= myParentStory.paragraphs[0];

          if (myFirstGraf.notes.length>0) {

              while (myFirstGraf.length == myFirstGraf.notes.length + 1) {

                          myFirstGraf.characters.item(-1).remove(); // remove paragraph return

                          var myFirstGraf= myParentStory.paragraphs[0]; //reset variable to new first graf

                      } // end while

              } // end if

           

          Is it dangerous? Foolish? Verbose?

          • 2. Re: Remove the line-ender but keep the note
            Marc Autret Level 4

            Hi Robert,

             

            Here is an alternative approach—quite experimental!—which should deal the same way with all text markers (notes, index, etc.):

             

            var m, t = myParentStory.texts;
            
            while( m=t[0].paragraphs[0].contents.match(/^(\uFEFF*)\r/) )
                t[0].characters[m[1].length].remove();
            

             

            Just for fun ;-)

             

            @+

            Marc