Fix Renderer - again

bzr-revno: 1735
This commit is contained in:
Andreas Preikschat 2011-08-30 19:10:52 +01:00 committed by Tim Bentley
commit d85128829e

View File

@ -233,26 +233,23 @@ class Renderer(object):
len(pages) > 1 and u'[---]' in text: len(pages) > 1 and u'[---]' in text:
pages = [] pages = []
while True: while True:
# Check if the first two potential virtual slides will fit slides = text.split(u'\n[---]\n', 2)
# (as a whole) on one slide. # If there are (at least) two occurrences of [---] we use
html_text = expand_tags( # the first two slides (and neglect the last for now).
u'\n'.join(text.split(u'\n[---]\n', 2)[:-1])) if len(slides) == 3:
html_text = expand_tags(u'\n'.join(slides[:2]))
# We check both slides to determine if the virtual break is
# needed (there is only one virtual break).
else:
html_text = expand_tags(u'\n'.join(slides))
html_text = html_text.replace(u'\n', u'<br>') html_text = html_text.replace(u'\n', u'<br>')
if self._text_fits_on_slide(html_text): if self._text_fits_on_slide(html_text):
# The first two virtual slides fit (as a whole) on one # The first two virtual slides fit (as a whole) on one
# slide. Replace the occurrences of [---]. # slide. Replace the first occurrence of [---].
text = text.replace(u'\n[---]', u'', 2)
else:
# The first two virtual slides did not fit as a whole.
# Check if the first virtual slide will fit.
html_text = expand_tags(text.split(u'\n[---]\n', 1)[1])
html_text = html_text.replace(u'\n', u'<br>')
if self._text_fits_on_slide(html_text):
# The first virtual slide fits, so remove it.
text = text.replace(u'\n[---]', u'', 1) text = text.replace(u'\n[---]', u'', 1)
else: else:
# The first virtual slide does not fit, which means # The first virtual slide fits, which means we have to
# we have to render the first virtual slide. # render the first virtual slide.
text_contains_break = u'[---]' in text text_contains_break = u'[---]' in text
if text_contains_break: if text_contains_break:
text_to_render, text = text.split(u'\n[---]\n', 1) text_to_render, text = text.split(u'\n[---]\n', 1)
@ -262,8 +259,7 @@ class Renderer(object):
lines = text_to_render.strip(u'\n').split(u'\n') lines = text_to_render.strip(u'\n').split(u'\n')
slides = self._paginate_slide(lines, line_end) slides = self._paginate_slide(lines, line_end)
if len(slides) > 1 and text: if len(slides) > 1 and text:
# Add all slides apart from the last one the # Add all slides apart from the last one the list.
# list.
pages.extend(slides[:-1]) pages.extend(slides[:-1])
if text_contains_break: if text_contains_break:
text = slides[-1] + u'\n[---]\n' + text text = slides[-1] + u'\n[---]\n' + text