Skip to content

Commit

Permalink
Do not emit manpage OSC 8 hyperlinks for anchor references (#12260)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
krobelus committed Apr 29, 2024
1 parent 7c7f0d7 commit 95a8553
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions sphinx/writers/manpage.py
Expand Up @@ -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}'")

Expand All @@ -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:'):
Expand All @@ -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
Expand Down

0 comments on commit 95a8553

Please sign in to comment.