From 95a85534877f4859ad136fc35144fb3e579d1e53 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Mon, 29 Apr 2024 02:24:04 +0200 Subject: [PATCH] Do not emit manpage OSC 8 hyperlinks for anchor references (#12260) A reference like ":ref:`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. --- sphinx/writers/manpage.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sphinx/writers/manpage.py b/sphinx/writers/manpage.py index d2d6dc5bf37..9c01ce67880 100644 --- a/sphinx/writers/manpage.py +++ b/sphinx/writers/manpage.py @@ -309,7 +309,8 @@ def visit_image(self, node: Element) -> None: # overwritten -- don't visit inner marked up nodes def visit_reference(self, node: Element) -> None: uri = node.get('refuri', '') - if uri: + is_safe_to_click = uri.startswith(('mailto:', 'http:', 'https:', 'ftp:')) + if is_safe_to_click: # OSC 8 link start (using groff's device control directive). self.body.append(fr"\X'tty: link {uri}'") @@ -319,7 +320,7 @@ def visit_reference(self, node: Element) -> None: self.visit_Text(node) self.body.append(self.defs['reference'][1]) - if uri.startswith(('mailto:', 'http:', 'https:', 'ftp:')): + if uri and not uri.startswith('#'): # if configured, put the URL after the link if self.config.man_show_urls and node.astext() != uri: if uri.startswith('mailto:'): @@ -328,7 +329,7 @@ def visit_reference(self, node: Element) -> None: ' <', self.defs['strong'][0], uri, self.defs['strong'][1], '>']) - if uri: + if is_safe_to_click: # OSC 8 link end. self.body.append(r"\X'tty: link'") raise nodes.SkipNode