Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ packages = [ "sphinxlint" ]
[tool.hatch.version.raw-options]
local_scheme = "no-local-version"

[tool.black]

[tool.ruff]
fix = true

Expand Down
16 changes: 11 additions & 5 deletions sphinxlint/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,23 +261,29 @@ def check_missing_underscore_after_hyperlink(file, lines, options=None):
URLs within download directives don't need trailing underscores.
https://www.sphinx-doc.org/en/master/usage/referencing.html#role-download
"""
for lno, line in enumerate(lines, start=1):
if "`" not in line:
for paragraph_lno, paragraph in paragraphs(lines):
if "`" not in paragraph:
continue
for match in rst.SEEMS_HYPERLINK_RE.finditer(line):
for match in rst.SEEMS_HYPERLINK_RE.finditer(paragraph):
if not match.group(2):
# Check if this is within any download directive on the line
# Include optional underscore in pattern to handle both cases
is_in_download = False
for download_match in rst.HYPERLINK_WITHIN_DOWNLOAD_RE.finditer(line):
for download_match in rst.HYPERLINK_WITHIN_DOWNLOAD_RE.finditer(
paragraph
):
if (
match.start() >= download_match.start()
and match.end() <= download_match.end()
):
is_in_download = True
break
if not is_in_download:
yield lno, "missing underscore after closing backtick in hyperlink"
error_offset = paragraph[: match.start()].count("\n")
yield (
paragraph_lno + error_offset,
"missing underscore after closing backtick in hyperlink",
)


@checker(".rst", ".po")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.. expect: missing underscore after closing backtick in hyperlink (missing-underscore-after-hyperlink)

`Link text
<https://example.com/>`
Loading