4 Replies Latest reply on Apr 6, 2010 2:46 AM by Peter Kahrel

    [JS CS4] Sort paragraphs

    Mityura

      Dear friends, please advise me a SIMPLE example of sorting paragraphs.

        • 1. Re: [JS CS4] Sort paragraphs
          Peter Kahrel Adobe Community Professional & MVP

          This is the simple one. Place the cursor somewhere in the story whose paragraphs you want to sort, then run this script:

           

          myParagraphs = app.selection[0].parentStory.contents.split ("\r");

          app.selection[0].parentStory.contents = myParagraphs.sort ().join ("\r");

           

          This works well only on paragraphs without any formatting. Also, accented latters are sorted after non-accented ones, which is wrong in many cases. To deal with situations like that (and many others), use http://www.kahrel.plus.com/indesign/sort.html

           

          Peter

          • 2. Re: [JS CS4] Sort paragraphs
            Mityura Level 1

            Thanks, Peter! Very simple and works.

             

            But how can I sort paragraphs in the following example:

             

            11111

                      some text bla-bla

                      text some bla-bla

                      bla-bla some text

                      some bla-bla text

            22222

                      some text bla-bla

                      text some bla-bla

                      bla-bla some text

                      some bla-bla text

            33333

                      some text bla-bla

                      text some bla-bla

                      bla-bla some text

                      some bla-bla text

            44444

                      some text bla-bla

                      text some bla-bla

                      bla-bla some text

                      some bla-bla text

            ...

             

            It is necessary, that headings (numbers or any text) remained on a place, and paragraphs between them were sorted.

            What way?

            • 3. Re: [JS CS4] Sort paragraphs
              [Jongware] Most Valuable Participant

              That's no longer possible with a simple sort ..

              • 4. Re: [JS CS4] Sort paragraphs
                Peter Kahrel Adobe Community Professional & MVP

                As Jongware said, that's not possible with a simple sort. What you'd have to do is rebuild your list into one that can be sorted, then sort it, and finally rebuild the list's original structure.

                 

                Step 1: replace all indents with some place holder so you can find them later on

                 

                11111@@some text bla-bla@@text some  bla-bla

                22222@@some text bla-bla@@text some  bla-bla

                33333@@some text bla-bla@@text some  bla-bla

                44444@@some text bla-bla@@text some  bla-bla

                 

                Step 2: sort the list

                 

                Step 3: replace @@ with \r\t (or whatever you use for indents).

                 

                Peter