summaryrefslogtreecommitdiff
path: root/presentty
diff options
context:
space:
mode:
authorJames E. Blair <corvus@gnu.org>2017-05-02 17:39:11 -0700
committerJames E. Blair <corvus@gnu.org>2017-05-02 18:13:09 -0700
commit308a06134d7749638c7ba3afcc4031f31ba09930 (patch)
tree121ae8f0518fdd816e2210cec2078e209d65ad45 /presentty
parent66b97688aa3945e1e9671e8400f57ce7c0943533 (diff)
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.
Diffstat (limited to 'presentty')
-rw-r--r--presentty/rst.py10
1 files changed, 9 insertions, 1 deletions
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):
253 pad = slide.SlidePadding(text, width='pack') 253 pad = slide.SlidePadding(text, width='pack')
254 self._append(node, pad, 'pack') 254 self._append(node, pad, 'pack')
255 255
256 def visit_line_block(self, node):
257 self.stack.append(slide.SlidePile([]))
258
259 def depart_line_block(self, node):
260 pile = self.stack.pop()
261 pad = slide.SlidePadding(pile, left=2)
262 self._append(node, pad, 'pack')
263
256 visit_line = visit_textelement 264 visit_line = visit_textelement
257 265
258 def depart_line(self, node): 266 def depart_line(self, node):
259 text = self.stack.pop() 267 text = self.stack.pop()
260 self._append(node, urwid.Text(text.getFormattedText(), wrap='clip'), 268 self._append(node, urwid.Text(text.getFlowedText(), wrap='clip'),
261 'pack') 269 'pack')
262 270
263 visit_title = visit_textelement 271 visit_title = visit_textelement