From a4dc2e496f6ed68d904931565cb7a87575368c44 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Fri, 10 Apr 2020 15:06:56 -0700 Subject: [PATCH] Add rudimentary preview link coloring --- amanuensis/parser/render.py | 22 +++++++++++++++++++--- amanuensis/server/lexicon.py | 3 ++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/amanuensis/parser/render.py b/amanuensis/parser/render.py index c6c00a4..5eb0338 100644 --- a/amanuensis/parser/render.py +++ b/amanuensis/parser/render.py @@ -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'

{"".join(span.recurse(self))}

' def SignatureParagraph(self, span): - return ('

' + return ( + '


' f'{"".join(span.recurse(self))}' - '

') + '

' + ) def BoldSpan(self, span): return f'{"".join(span.recurse(self))}' @@ -29,4 +38,11 @@ class PreviewHtmlRenderer(): return f'{"".join(span.recurse(self))}' def CitationSpan(self, span): - return f'{"".join(span.recurse(self))}' + 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'{"".join(span.recurse(self))}' diff --git a/amanuensis/server/lexicon.py b/amanuensis/server/lexicon.py index ec5710d..0499174 100644 --- a/amanuensis/server/lexicon.py +++ b/amanuensis/server/lexicon.py @@ -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"]}'