Skip to content

Commit

Permalink
LaTeX: support link to #
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeier committed May 21, 2023
1 parent 4d780a4 commit 3050999
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/nbsphinx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1183,12 +1183,12 @@ def _local_file_from_reference(node, document):
if not refuri:
# Target doesn't have URI
return '', ''
if '://' in refuri:
# Not a local link
return '', ''
elif refuri.startswith('#') or refuri.startswith('mailto:'):
if '://' in refuri or refuri.startswith('mailto:'):
# Not a local link
return '', ''
elif refuri.startswith('#'):
# Kinda not a local link
return '', refuri

# NB: We look for "fragment identifier" before unquoting
match = re.match(r'^([^#]*)(#.*)$', refuri)
Expand Down Expand Up @@ -1229,7 +1229,13 @@ def apply(self):
filename, fragment = _local_file_from_reference(
node, self.document)
if not filename:
continue
if fragment == '#':
# This would work automagically in the HTML builder,
# but it is needed for LaTeX.
filename = os.path.basename(env.doc2path(env.docname))
fragment = ''
else:
continue

for s in env.config.source_suffix:
if filename.lower().endswith(s.lower()):
Expand Down

0 comments on commit 3050999

Please sign in to comment.