Make the recursion nicer
This commit is contained in:
parent
b5efe8c361
commit
26a0e38154
|
@ -10,16 +10,16 @@ class PreviewHtmlRenderer():
|
|||
def LineBreak(self, span):
|
||||
return '<br>'
|
||||
def ParsedArticle(self, span):
|
||||
return '\n'.join([child.render(self) for child in span.spans])
|
||||
return '\n'.join(span.recurse(self))
|
||||
def BodyParagraph(self, span):
|
||||
return f'<p>{"".join([child.render(self) for child in span.spans])}</p>'
|
||||
return f'<p>{"".join(span.recurse(self))}</p>'
|
||||
def SignatureParagraph(self, span):
|
||||
return ('<hr><span class="signature"><p>'
|
||||
f'{"".join([child.render(self) for child in span.spans])}'
|
||||
f'{"".join(span.recurse(self))}'
|
||||
'</p></span>')
|
||||
def BoldSpan(self, span):
|
||||
return f'<b>{"".join([child.render(self) for child in span.spans])}</b>'
|
||||
return f'<b>{"".join(span.recurse(self))}</b>'
|
||||
def ItalicSpan(self, span):
|
||||
return f'<i>{"".join([child.render(self) for child in span.spans])}</i>'
|
||||
return f'<i>{"".join(span.recurse(self))}</i>'
|
||||
def CitationSpan(self, span):
|
||||
return f'<a href="#">{span.cite_text}</a>'
|
||||
|
|
|
@ -29,6 +29,8 @@ class SpanContainer(Renderable):
|
|||
self.spans = spans
|
||||
def __str__(self):
|
||||
return f"[{type(self).__name__} {' '.join([str(span) for span in self.spans])}]"
|
||||
def recurse(self, renderer):
|
||||
return [child.render(renderer) for child in self.spans]
|
||||
|
||||
class ParsedArticle(SpanContainer):
|
||||
"""Multiple paragraphs"""
|
||||
|
|
Loading…
Reference in New Issue