From 308a06134d7749638c7ba3afcc4031f31ba09930 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Tue, 2 May 2017 17:39:11 -0700 Subject: Use getFlowedText in line block elements A line block is essentially a kind of block quote. A '|' at the start of a line forces a new line. A subsequent line starting with a space is a continuation of the previous line. Indentation within a line block creates a nested line block. When the line block (or series of nested blocks) is finished, there should be a blank line separating it from the next element. Sphinx produces a 'line_block' event for each block (that is, series of lines, or nested group of lines), and a 'line' event for each line within that block. Currently, each of those line events accumulates text and then uses the formatted version of that text when creating urwid widgets. However, in the case of a continuation line, both lines from the source file appear in the same line event. This suggests that the correct action is to use the flowed version of the text we accumulate. In other words, the current behavior erroneously preserves the formatting of continuation lines, whereas by spec, it should not. The switch to getFlowedText corrects this. Additionally, because we are ignoring line_block events, it was not possible to create nested line_blocks. By treating them in the same manner as block quotes, where we put the contents inside of an urwid widget with left-hand padding, the resulting line block groupings are nested as expected. --- example/demo.rst | 19 +++++++++++++++++++ presentty/rst.py | 10 +++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/example/demo.rst b/example/demo.rst index b7ee4bb..ad8ae77 100644 --- a/example/demo.rst +++ b/example/demo.rst @@ -68,6 +68,25 @@ Table F T === === +Line Blocks +=========== +| +| I bring fresh showers for the thirsting flowers, +| From the seas and the streams; +| I bear light shade for the leaves when laid +| In their noonday dreams. +| From my wings are shaken the dews that waken +| The sweet buds every one, +| When rocked to rest on their mother's breast, +| As she dances about the sun. +| I wield the flail of the lashing hail, +| And whiten the green plains under, +| And then again I dissolve it in rain, +| And laugh as I pass in thunder. +| + +(From "The Cloud", Percy Bysshe Shelley) + Dissolve Transition =================== Transitions may be "dissolve," where one slide cross-fades into the next... diff --git a/presentty/rst.py b/presentty/rst.py index b4258da..5867ca1 100644 --- a/presentty/rst.py +++ b/presentty/rst.py @@ -253,11 +253,19 @@ class UrwidTranslator(docutils.nodes.GenericNodeVisitor): pad = slide.SlidePadding(text, width='pack') self._append(node, pad, 'pack') + def visit_line_block(self, node): + self.stack.append(slide.SlidePile([])) + + def depart_line_block(self, node): + pile = self.stack.pop() + pad = slide.SlidePadding(pile, left=2) + self._append(node, pad, 'pack') + visit_line = visit_textelement def depart_line(self, node): text = self.stack.pop() - self._append(node, urwid.Text(text.getFormattedText(), wrap='clip'), + self._append(node, urwid.Text(text.getFlowedText(), wrap='clip'), 'pack') visit_title = visit_textelement -- cgit v1.2.3