From 1f53129848f904b1d4cb2edba1687d7eebdac9ef Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Sun, 22 Sep 2019 03:45:28 +1000 Subject: [PATCH] Implement Markdown hyperlinks --- legalmd/latex_renderer.py | 8 ++++++++ legalmd/rtf_renderer.py | 8 ++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/legalmd/latex_renderer.py b/legalmd/latex_renderer.py index c36bb22..87cafdf 100644 --- a/legalmd/latex_renderer.py +++ b/legalmd/latex_renderer.py @@ -52,6 +52,14 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer): result = result.replace('★★★', r'\texorpdfstring{\freeserif ★★★}{★★★}') return result + def render_link(self, token): + template = '\\href{{{target}}}{{{inner}}}' + inner = self.render_inner(token) + return template.format(target=token.target, inner=inner) + + def render_auto_link(self, token): + return '\\url{{{}}}'.format(token.target) + def render_cross_reference(self, token): reference = token.get_reference() if not reference: diff --git a/legalmd/rtf_renderer.py b/legalmd/rtf_renderer.py index 79f9f31..c33335c 100644 --- a/legalmd/rtf_renderer.py +++ b/legalmd/rtf_renderer.py @@ -68,13 +68,13 @@ class RTFRenderer(mistletoe.base_renderer.BaseRenderer): raise Exception('NYI') def render_link(self, token): - raise Exception('NYI') + return r'{{\field{{\*\fldinst{{HYPERLINK "{target}"}}}}{{\fldrslt{{\ul\cf1 {inner}}}}}}}'.format(target=token.target, inner=self.render_inner(token)) def render_auto_link(self, token): - raise Exception('NYI') + return self.render_link(token) def render_escape_sequence(self, token): - raise Exception('NYI') + return self.render_inner(token) def render_cross_reference(self, token): return '{reference_type}{reference_num}'.format( @@ -257,7 +257,7 @@ class RTFRenderer(mistletoe.base_renderer.BaseRenderer): ) def render_document(self, token): - result_str = format(r'{\rtf1\deff0{\fonttbl{\f0 TeX Gyre Heros{\*\falt FreeSans}{\*\falt Liberation Sans}{\*\falt Arial};}}\paperw\paperh\margl\margr\margt\margb{\header\f0\fs16\tqr\tx \tab <author>}{\footer\f0\fs16\tqr\tx<flushright> <footer>\tab\chpgn}\fs1\~\par\sa<parskip>\fs24 <inner>}', + result_str = format(r'{\rtf1\deff0{\fonttbl{\f0 TeX Gyre Heros{\*\falt FreeSans}{\*\falt Liberation Sans}{\*\falt Arial};}}{\colortbl;\red0\green0\blue0\;\red0\green0\blue255;}{\info{\title <title>}{\author https://gitlab.com/RunasSudo/legalmd}}\paperw<paperw>\paperh<paperh>\margl<margin>\margr<margin>\margt<margin>\margb<margin>{\header\f0\fs16\tqr\tx<flushright> <title>\tab <author>}{\footer\f0\fs16\tqr\tx<flushright> <footer>\tab\chpgn}\fs1\~\par\sa<parskip>\fs24 <inner>}', paperw=cm_to_twip(21), paperh=cm_to_twip(29.7), margin=cm_to_twip(2),