Don't generate hyperlinks for un-referenceable headings/items (e.g. inside quotes)

This commit is contained in:
RunasSudo 2019-09-15 00:32:48 +10:00
parent c4481addf3
commit 071e6db304
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

View File

@ -93,11 +93,14 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
)
def render_numbered_heading(self, token):
if token.full_label():
sha = hashlib.sha256()
sha.update(token.full_label().encode('utf-8'))
hyperlink = format(r'\hypertarget{<linkname>}{}',
linkname=sha.hexdigest()
)
else:
hyperlink = '{}'
if token.level == 1:
# Part
@ -155,11 +158,14 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
def render_subrules_item(self, token):
if token.label:
if token.full_label():
sha = hashlib.sha256()
sha.update(token.full_label().encode('utf-8'))
hyperlink = format(r'\hypertarget{<linkname>}{}',
linkname=sha.hexdigest()
)
else:
hyperlink = '{}'
return format(r'\N{\par<hyperlink>\leftskip=\dimexpr\quotemargin+<lmarg>+<level>cm\relax\hangindent=1cm\parskip=<parskip>\makebox[<lmarg>][l]{<label>}<content>\par}\N',
hyperlink=hyperlink,