13 Replies Latest reply on Aug 30, 2016 9:27 AM by shermz

    Numbered list issue making Code Syntax highlighter in InDesign using Paragraph Styles

    shermz

      Using GREP styles in paragraph styles options I have managed to make useful, HTML, CSS, and Javascript, syntax highlighter styles.

      Code can be copied and pasted or can be typed and the styles work well.codehighlighter_indesign.jpg.

       

      My only issue is with numbering.

       

      I have set up an ordered list character for my bullet type.

      Though the character size must be larger than the type size of the code to get the bar character to connect and be a solid line.

       

      Is there a way to have the same font size for numbering and code and a bar character that will connect? Not be broken as the separator between numbered lines and code?

       

      Also there doesn't appear to be a way to alter the color or weight of the bar (It must be the same color as the number) and have an automatically generating bar? It possible?

        • 1. Re: Numbered list issue making Code Syntax highlighter in InDesign using Paragraph Styles
          shermz Level 1

          Actually this doesn't work. Just realized the next code block will start at the last line number left off on.

          • 3. Re: Numbered list issue making Code Syntax highlighter in InDesign using Paragraph Styles
            Trevorׅ Adobe Community Professional

            Come on ohmnath, I mean if the OP was trying to make an InDesign paragraph style suited to medical needs would you forward it within about 1/2 an hour to a doctors forum?

            The OP is asking a regular paragraph style question about how to make a style with numbers suitable for displaying code. He is not asking about scripting, that is more suited to the regular ID forum.

            In my opinion back to the ID forum.

             

            Trevor

            • 4. Re: Numbered list issue making Code Syntax highlighter in InDesign using Paragraph Styles
              ohmnath Adobe Employee

              Hi Trevorׅ,

               

              My mistake. I misread it. Moved back to InDesign.

               

              Regards,

              Om

              • 5. Re: Numbered list issue making Code Syntax highlighter in InDesign using Paragraph Styles
                Laubender Adobe Community Professional & MVP

                Hi,

                since you are working with Adobe Source Code Pro as font you have an alternative for the character VERTICAL LINE (Unicode 007C):
                Just use BOX DRAWINGS LIGHT VERTICAL (Unicode 2502):

                 

                BOX DRAWINGS LIGHT VERTICAL-1.png

                 

                BOX DRAWINGS LIGHT VERTICAL-2.png

                 

                The two screenshots are from my German InDesign, but I think you'll get the idea.

                 

                Best,
                Uwe

                1 person found this helpful
                • 6. Re: Numbered list issue making Code Syntax highlighter in InDesign using Paragraph Styles
                  Laubender Adobe Community Professional & MVP

                  For the second question, how the color of the bar can be changed independently from the number, I have no good answer.
                  Not within one numbered list.

                   

                  The alternative:

                  You could split the task into two text frames.

                  The left one for a numbered list. Right to it your code with a bullet list using a different character style and BOX DRAWINGS LIGHT VERTICAL (Unicode 2502) as bullet:

                   

                  TwoTextFrames-NumberedList-BulletPlusSourceCode.png

                   

                  Also possible:
                  A table with two columns. Where the second cell of every row contains exactly one line of code.

                  In case you need a paragraph sign at the end of every cell (e.g. for a numbering list), use a leading with 0 points.

                   

                  TwoColumnTable.png

                   

                   

                  Regards,
                  Uwe

                  1 person found this helpful
                  • 7. Re: Numbered list issue making Code Syntax highlighter in InDesign using Paragraph Styles
                    Joel Cherney Level 5

                    Code can be copied and pasted or can be typed and the styles work well..

                    [...]

                    My only issue is with numbering.

                     

                    Uwe's suggestions are really good. If I were working on a long document with many code samples, and I needed the bar to be in a color different from the numbering, I would:

                     

                    1) Complete the book with un-colored vertical bars.

                    2) I mean, really complete it. It's about to go to press.

                    3) Before I send it off, I will do a Find for the code-sample paragraph style.

                    4) In every instance of that paragraph style, I will convert bullet and numbering to live text, and then

                    5) write a GREP style that will apply a character style (with my desired color) to all instances of BOX DRAWINGS LIGHT VERTICAL that are present in the code-sample paragraph style.

                    6) Then I'll do a final proof to make sure I haven't fubared anything.

                     

                    There are plenty of places in a document production workflow where we want stuff to Just Happen Automagically. However, sometimes it's easier and faster to do it manually. If you were willing to, I dunno, anchor an object, or use a GREP query to start all lines of code with a BOX DRAWINGS LIGHT VERTICAL glyph,  or lay out your code in a table, or... heck, or use Wordperfect. WP was great at that kind of legal-numbering stuff. If you were willing to do any of those things, you'd be set.

                     

                    Can you tell us what the advantage is of having all of the live text in your code samples be code, without any of the formatting or line numbers or et cetera? Do you need something that is perfectly formatted once you've pasted or keyed your code in, or are you willing to do some formatting work on it after the content is in place? Maybe we can figure out which duct-tape kludge will work best for you.

                    • 8. Re: Numbered list issue making Code Syntax highlighter in InDesign using Paragraph Styles
                      Laubender Adobe Community Professional & MVP

                      Hi Joel,

                      thank you for your comments.
                      By any means I would avoid mixing code contents with contents for numbering.

                       

                      If one exports to PDF and the user should be able to extract code from samples by copy/paste the line numbers must not go along. Code would break, if the line numbers come along and are pasted to a script editor.

                       

                      So using a numbered list and/or bullets of a certain kind would be the way to go.
                      We are able to clearly part contents (the raw code) from formatting (coloring, numbering etc.pp.).

                       

                      One question should be discussed a bit more, I think:
                      What is considered a line of code that is numbered?

                       

                      E.g. if we take an app like the ExtendScript Toolkit (ESTK) one numbered line is defined by the use of a paragraph sign or a discretionary line break. Even if we set the ESTK to a mode that would break long lines automatically at the end of the script editor window.

                       

                      For practical reasons, discretionary line breaks should be avoided in code typesetting, if one wants automatical numbering with a numbered list that only can do that on whole paragraphs.

                       

                      Apart from a bulleted lists what can we do to include a bar with formatting and not using tables?

                      With InDesign CC 2015 we have a new opportunity: Paragraph Shading
                      It's not as flexible as we might like, but it's good enough to solve the "bar" problem.

                       

                      Regards,
                      Uwe

                      • 9. Re: Numbered list issue making Code Syntax highlighter in InDesign using Paragraph Styles
                        Laubender Adobe Community Professional & MVP

                        Here an example from my German InDesign CC 2015.4 where I did the numbering with a numbered list and the bar with paragraph shading:

                         

                        Code-LineNumbering-Bar-ParagraphShading-1.png

                         

                        Code-LineNumbering-Bar-ParagraphShading-2.png

                         

                        Code-LineNumbering-Bar-ParagraphShading-3.png

                         

                        Be aware, that the width of the "bar" would change, if you change the width of the text frame.

                        5 mm added to the width of the text frame:

                         

                        Code-LineNumbering-Bar-ParagraphShading-4.png

                         

                        Or would vanish.

                        Width of original text frame diminished by 5 mm:

                         

                        Code-LineNumbering-Bar-ParagraphShading-5.png

                         

                        Regards,
                        Uwe

                        2 people found this helpful
                        • 10. Re: Numbered list issue making Code Syntax highlighter in InDesign using Paragraph Styles
                          Laubender Adobe Community Professional & MVP

                          If you are using different text frames for code samples (different width) you could use different paragraph styles with different paragraph shading settings dependent on the width of the text frames. If the text frames are not threaded to other text frames you could simply apply different object styles to the text frames.

                           

                          Regards,
                          Uwe

                          • 11. Re: Numbered list issue making Code Syntax highlighter in InDesign using Paragraph Styles
                            Trevorׅ Adobe Community Professional

                            Hi Uwe,

                             

                            I like the shading option.

                            If the end result is going to be PDFs then I would vote for the 2 frame option for ease of copying the code without the numbers.

                            Otherwise the one frame option is easier.

                            I don't think it would take more than a few minutes to put a script together to add a text frame next to the code frame and place the line numbers in it, that would make it easy to maintain the 2 textFrame option.

                             

                            shermz I think your question has been answered and you should mark one of Uwe's answers as correct

                             

                            Regards,

                             

                            Trevor

                            • 12. Re: Numbered list issue making Code Syntax highlighter in InDesign using Paragraph Styles
                              Laubender Adobe Community Professional & MVP

                              Trevorׅ wrote:


                              If the end result is going to be PDFs then I would vote for the 2 frame option for ease of copying the code without the numbers.

                              Otherwise the one frame option is easier.

                              Yes. And the paragraph shading option would be applied to the text of the text frame doing the numbering of lines.

                              So we can strictly separate formatting from contents of the code.

                               

                              And you are right, it would require a script to synch the position of the numbering if we allow line breaks in the code and want only number "real" paragraphs in the code. If that script can be written in a few minutes will depend on if text frames containing the code a threaded throughout the document. Maybe it will take only some minutes to an hour to write it, but it will definitely take some hours to test it and adapt it for needs we cannot foresee now: E.g. anchored text frames containing code and other special cases.

                               

                              Regards,
                              Uwe

                              • 13. Re: Numbered list issue making Code Syntax highlighter in InDesign using Paragraph Styles
                                shermz Level 1

                                Thank you all!

                                 

                                All great answers!

                                 

                                I think paragraph shading is totally the way to go here. Just tried it and it does the job. It looks good and is easy enough to implement.

                                 

                                Actually the black behind my first screenshot is paragraph shading. I set it to black to separate documentation from code examples and to be able to style each type of text chunk in my documentation with one click.

                                Now since everything is in tables I'm just pasting table cells with a black background and the code in them. And now I get the benefit of being able to style an outline around the code blocks.

                                 

                                I too think it would be cool to have more options for paragraph shading at some point. Like an outline would be great.

                                And being able to specify a character style for ordered lists markers glyphs as well as one for numbers would be cool.

                                 

                                But this works great for pretty much any automatic syntax highlighter and is real easy to use and fine tune to fit whatever theme I may want.

                                 

                                Thanks,

                                Shermz

                                 

                                codehighlighter_example_indesign.jpg