Skip to content

Commit

Permalink
[manpage] don't emit OSC 8 hyperlinks for anchor references (sphinx-d…
Browse files Browse the repository at this point in the history
…oc#12108)

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 terminals
that implements a hint mode for selecting links -- the extra links
add noise, making it harder to select the interesting ones.

While at it, relax the restriction that "man_show_urls" is limited
to mailto/http/ftp URLs; I don't see why other protocols shouldn't
be allowed.

Follow up to sphinx-doc#12108

I also confirmed that even with docutils 0.21 we do not need to
override depart_reference because we already skip reference nodes.
  • Loading branch information
krobelus committed Apr 10, 2024
1 parent 6fd8b30 commit 4d82101
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions sphinx/writers/manpage.py
Original file line number Diff line number Diff line change
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_local_reference = uri.startswith('#')
if uri and not is_local_reference:
# 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 not is_local_reference:
# 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 uri and not is_local_reference:
# OSC 8 link end.
self.body.append(r"\X'tty: link'")
raise nodes.SkipNode
Expand Down

0 comments on commit 4d82101

Please sign in to comment.