Skip to content

Commit 95a8553

Browse files
authored
Do not emit manpage OSC 8 hyperlinks for anchor references (#12260)
A reference like ":ref:`Some other page <some-other-page>`" results in a refuri "#some-other-page". This does not seem useful to readers of the man page. It is especially unhelpful when using a terminal that implements a hint mode for selecting links -- the extra links add noise, making it harder to select the interesting ones. Don't emit OSC 8 for those.
1 parent 7c7f0d7 commit 95a8553

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

sphinx/writers/manpage.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ def visit_image(self, node: Element) -> None:
309309
# overwritten -- don't visit inner marked up nodes
310310
def visit_reference(self, node: Element) -> None:
311311
uri = node.get('refuri', '')
312-
if uri:
312+
is_safe_to_click = uri.startswith(('mailto:', 'http:', 'https:', 'ftp:'))
313+
if is_safe_to_click:
313314
# OSC 8 link start (using groff's device control directive).
314315
self.body.append(fr"\X'tty: link {uri}'")
315316

@@ -319,7 +320,7 @@ def visit_reference(self, node: Element) -> None:
319320
self.visit_Text(node)
320321
self.body.append(self.defs['reference'][1])
321322

322-
if uri.startswith(('mailto:', 'http:', 'https:', 'ftp:')):
323+
if uri and not uri.startswith('#'):
323324
# if configured, put the URL after the link
324325
if self.config.man_show_urls and node.astext() != uri:
325326
if uri.startswith('mailto:'):
@@ -328,7 +329,7 @@ def visit_reference(self, node: Element) -> None:
328329
' <',
329330
self.defs['strong'][0], uri, self.defs['strong'][1],
330331
'>'])
331-
if uri:
332+
if is_safe_to_click:
332333
# OSC 8 link end.
333334
self.body.append(r"\X'tty: link'")
334335
raise nodes.SkipNode

0 commit comments

Comments
 (0)