Implement Markdown hyperlinks

This commit is contained in:
RunasSudo 2019-09-22 03:45:28 +10:00
parent 7a7227e309
commit 1f53129848
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 12 additions and 4 deletions

View File

@ -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:

View File

@ -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<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>}',
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),