@@ -246,17 +246,22 @@ def check_missing_space_in_hyperlink(file, lines, options=None):
246246 if "`" not in line :
247247 continue
248248 for match in rst .SEEMS_HYPERLINK_RE .finditer (line ):
249- if not match .group (1 ):
249+ if not match .group (2 ):
250250 yield lno , "missing space before < in hyperlink"
251251
252252
253253@checker (".rst" , ".po" )
254254def check_missing_underscore_after_hyperlink (file , lines , options = None ):
255- """Search for hyperlinks missing underscore after their closing backtick.
255+ """Search for hyperlinks with incorrect underscore usage after closing backtick.
256256
257+ For regular hyperlinks:
257258 Bad: `Link text <https://example.com>`
258259 Good: `Link text <https://example.com>`_
259260
261+ For hyperlinks within download directives:
262+ Bad: :download:`file <https://example.com>`_
263+ Good: :download:`file <https://example.com>`
264+
260265 Note:
261266 URLs within download directives don't need trailing underscores.
262267 https://www.sphinx-doc.org/en/master/usage/referencing.html#role-download
@@ -265,19 +270,15 @@ def check_missing_underscore_after_hyperlink(file, lines, options=None):
265270 if "`" not in line :
266271 continue
267272 for match in rst .SEEMS_HYPERLINK_RE .finditer (line ):
268- if not match .group (2 ):
269- # Check if this is within any download directive on the line
270- # Include optional underscore in pattern to handle both cases
271- is_in_download = False
272- for download_match in rst .HYPERLINK_WITHIN_DOWNLOAD_RE .finditer (line ):
273- if (
274- match .start () >= download_match .start ()
275- and match .end () <= download_match .end ()
276- ):
277- is_in_download = True
278- break
279- if not is_in_download :
280- yield lno , "missing underscore after closing backtick in hyperlink"
273+ is_in_download = bool (match .group (1 ))
274+ has_underscore = bool (match .group (3 ))
275+
276+ if is_in_download and has_underscore :
277+ yield lno , "unnecessary underscore after closing backtick in hyperlink"
278+ elif not is_in_download and not has_underscore :
279+ yield lno , "missing underscore after closing backtick in hyperlink"
280+ else :
281+ continue
281282
282283
283284@checker (".rst" , ".po" )
0 commit comments