Add rudimentary preview link coloring

This commit is contained in:
Tim Van Baak 2020-04-10 15:06:56 -07:00
parent aa4b94d0c1
commit a4dc2e496f
2 changed files with 21 additions and 4 deletions

View File

@ -5,6 +5,13 @@ readable formats.
class PreviewHtmlRenderer():
def __init__(self, article_map):
"""
article_map maps article titles to character ids. An article
present in the map but mapped to None is a phantom article.
"""
self.article_map = article_map
def TextSpan(self, span):
return span.innertext
@ -18,9 +25,11 @@ class PreviewHtmlRenderer():
return f'<p>{"".join(span.recurse(self))}</p>'
def SignatureParagraph(self, span):
return ('<hr><span class="signature"><p>'
return (
'<hr><span class="signature"><p>'
f'{"".join(span.recurse(self))}'
'</p></span>')
'</p></span>'
)
def BoldSpan(self, span):
return f'<b>{"".join(span.recurse(self))}</b>'
@ -29,4 +38,11 @@ class PreviewHtmlRenderer():
return f'<i>{"".join(span.recurse(self))}</i>'
def CitationSpan(self, span):
return f'<a href="#">{"".join(span.recurse(self))}</a>'
if span.cite_target in self.article_map:
if self.article_map.get(span.cite_target):
link_class = ' style="color:#0000ff"'
else:
link_class = ' style="color:#ff0000"'
else:
link_class = ' style="color:#008000"'
return f'<a href="#"{link_class}>{"".join(span.recurse(self))}</a>'

View File

@ -240,7 +240,8 @@ def get_bp():
article = request.json['article']
# TODO verification
parsed_draft = parse_raw_markdown(article['contents'])
rendered_html = parsed_draft.render(PreviewHtmlRenderer())
rendered_html = parsed_draft.render(PreviewHtmlRenderer(
{'Article':'default','Phantom':None}))
features = parsed_draft.render(FeatureCounter())
filename = f'{article["character"]}.{article["aid"]}'