[reportlab-users] Relative indents, nested lists and reST

Andy Robinson reportlab-users@reportlab.com
Fri, 2 May 2003 00:14:05 +0100


I won't have much time to look at paragraph implementations
until the weekend, but coding seemed more fun than working 
tonight :-)  I added one think which I think will really help
(and would be quite hard to plug in if you don't know
our main loop). 

There is now a concept of "relative indentation" or
"context-sensitive indentation" in Platypus.  One thing
reST and HTML rendering need is nested lists.  There is
a runnable example in
  reportlab/test/test_platypus_indents.py
which produces
  reportlab/test/test_platypus_indents.pdf


Let's say you want to do this in Platypus:

- level 1 bullet
- level 1 bullet again
   - level 2 bullet
   - level 2 bullet again
   Definition:
      Paragraph at this level of nexting

You would have to make a style for 'level 1 bullet para',
'level 2 bullet para' etc, track how indented you need to
be and dynamically select the right style.  What's missing 
is the ability to say "indent all stuff below here by 36 points" 
as you enter a list, and dedent again afterwards as you exit it.
If you are rendering HTML, you would do this when you saw the
<ul> and </ul>, and then use just one style for the bullets.

I added an Indenter ActionFlowable, and modified the main
loop slightly.  Indenter takes RELATIVE arguments which
modify the left and right margin of the frame, until the
next Indenter appears. So you can now do this:

story.append(Indenter(left=36, right=0) )
story.append('bullet point 1', bulletStyle) )
story.append('bullet point 2', bulletStyle) )
story.append(Indenter(left=36, right=0) )
story.append('nested bullet point 1', bulletStyle) )
story.append(Indenter(left=-72, right=0) )

To do this, frames have two new private attributes
_leftExtraIndent and _rightExtraIndent, and these are
set by an Indenter.  They 'carry over' from one 
frame to the next (and AFAICT work OK when switching
templates).

reST and HTML rendering will need a bunch of other stuff too
but I hope this helps...

- Andy