From 3050999fc19ebc0739792a9c42f5e991a2e994ca Mon Sep 17 00:00:00 2001 From: Matthias Geier Date: Mon, 17 Apr 2023 23:30:34 +0200 Subject: [PATCH] LaTeX: support link to # --- src/nbsphinx/__init__.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/nbsphinx/__init__.py b/src/nbsphinx/__init__.py index a21a381b..95de66ce 100644 --- a/src/nbsphinx/__init__.py +++ b/src/nbsphinx/__init__.py @@ -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) @@ -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()):