diff --git a/src/hieroglyph/tests/test_translator.py b/src/hieroglyph/tests/test_translator.py index 85e0329..71a2901 100644 --- a/src/hieroglyph/tests/test_translator.py +++ b/src/hieroglyph/tests/test_translator.py @@ -374,3 +374,68 @@ def test_rst_quote_makes_quote_slide(self): '\n\n\n\n\n', ], ) + + def test_unattributed_rst_quote_makes_quote_slide(self): + document = util.make_document( + 'quoted', + """\ +.. slide:: Quotes + :level: 2 + + reStructuredText quotes are automatically converted + +""", + ) + translator = SlideTranslator( + self.builder, + document, + ) + + document.walkabout(translator) + + self.assertEqual( + translator.body, + [ + u'\n
\n\n' + '

Quotes

\n\n' + '\n' + 'reStructuredText quotes are automatically converted\n' + '\n\n\n\n
', + ], + ) + + def test_rst_quote_processes_normally_with_extra_content(self): + document = util.make_document( + 'quoted', + """\ +.. slide:: Indented RST + :level: 2 + + This text is over indented. + + As is this text. + + They look like quotes but they're not. + +""", + ) + translator = SlideTranslator( + self.builder, + document, + ) + + document.walkabout(translator) + + self.assertEqual( + translator.body, + [ + u'\n
\n\n' + '

Indented RST

\n\n' + '
\n' + '

This text is over indented.

\n' + '

As is this text.

\n' + '

They look like quotes but they\'re not.

\n' + '
\n' + '\n\n\n\n
', + ], + ) diff --git a/src/hieroglyph/writer.py b/src/hieroglyph/writer.py index 20b3597..044c177 100644 --- a/src/hieroglyph/writer.py +++ b/src/hieroglyph/writer.py @@ -264,33 +264,37 @@ def depart_title(self, node): self.body.append(title) def visit_block_quote(self, node): - # first child must be a paragraph, process it as a element - p = node.children[0] - if p.tagname != 'paragraph': - raise ValueError("The first child of a quote must be a paragraph") - self.body.append(self.starttag(node, 'q')) - for text_item in p: - text_item.walkabout(self) - self.body.append('\n') - - if len(node.children) > 2: - raise ValueError("A quote can only have 2 children, the quote text" - " and an attribution") - # optional second child must be an attribution, processing as a
- # following the - if len(node.children) > 1: - attr = node.children[1] - if attr.tagname != 'attribution': - raise ValueError("The second child of a quote must be" - " an attribution") - - self.body.append(self.starttag(attr, 'div', CLASS="author")) - for text_item in attr: + quote_slide_tags = ['paragraph', 'attribution'] + + # see if this looks like a quote slide + if (len(node.children) <= 2 and + [c.tagname for c in node.children] == quote_slide_tags[:len(node.children)]): + + # process this as a quote slide + + # first child must be a paragraph, process it as a element + p = node.children[0] + self.body.append(self.starttag(node, 'q')) + for text_item in p: text_item.walkabout(self) - self.body.append('
\n') + self.body.append('\n') + + # optional second child must be an attribution, processing as a
+ # following the + if len(node.children) > 1: + attr = node.children[1] + + self.body.append(self.starttag(attr, 'div', CLASS="author")) + for text_item in attr: + text_item.walkabout(self) + self.body.append('
\n') + + # skip all normal processing + raise nodes.SkipNode + + else: + return HTMLTranslator.visit_block_quote(self, node) - # skip all normal processing - raise nodes.SkipNode class SlideTranslator(BaseSlideTranslator):