On Wednesday, January 2, 2013 10:02:40 AM UTC-6, Edward K. Ream wrote:
ReportTraverser uses this pattern at rev 288. It is a remarkable
simplification.
> The revised r.div method will be something like::
>
> def div(self,aList):
> compute old and new indents
> return [
> <div>, with old indent,
> aList, with new indent,
> </div>, with old indent,
> ]
>
This doesn't work! aList won't have the proper indentation. In
particular, the following won't work::
[[' ',z] for z in aList],
flatten_list will add the two spaces before the line, that is, before a
newline. Instead, a hack is needed:
return [
div,
join_list(aList,indent=' '),
'\n</div>'
]
The new 'indent' keyword tells flatten_list to add the given indentation
(two spaces, here), to strings that start with a newline. The new code in
flatten_list is::
for i,item in enumerate(aList):
if leading: yield leading
for s in flatten_list(item):
if indent:
if s.startswith('\n'):
yield '\n'+indent+s[1:]
else:
yield s
else:
yield s
if sep and i < len(aList)-1: yield sep
if trailing: yield trailing
The point is that the indentation must be "moved behind the newline".
Edward
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/leo-editor/-/8QSW7gamRksJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/leo-editor?hl=en.