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