Skip to content

Commit

Permalink
[bugfix] :link-icon: is same as :ref: for internal links
Browse files Browse the repository at this point in the history
  • Loading branch information
ftnext committed Oct 6, 2024
1 parent 87ebb5b commit eb35b66
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
17 changes: 14 additions & 3 deletions src/sphinx_new_tab_link/roles.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from urllib.parse import urlparse

from docutils import nodes
from sphinx.util.docutils import ReferenceRole

Expand All @@ -17,6 +19,15 @@ class IconLinkRole(ReferenceRole):
"""

def run(self) -> tuple[list[nodes.Node], list[nodes.system_message]]:
node = nodes.reference(text=self.title, refuri=self.target)
reference_with_icon = add_icon_to_reference(node)
return [reference_with_icon], []
parse_result = urlparse(self.target)
if parse_result.scheme:
node = nodes.reference(
text=self.title, refuri=self.target, internal=False
)
reference_with_icon = add_icon_to_reference(node)
return [reference_with_icon], []
else:
node = nodes.reference(
text=self.title, refuri=f"#{self.target}", internal=True
)
return [node], []
5 changes: 3 additions & 2 deletions tests/test_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ def test_see_external_link_with_icon(built_html_path: Path) -> None:
assert ref.text == "httpbin "


@pytest.mark.skip("TODO bugfix #19")
def test_see_internal_link_without_icon(built_html_path: Path) -> None:
references = extract_references(built_html_path)

assert_reference_is_not_external(references[2])
ref = references[2]
assert_reference_is_not_external(ref)
assert not ref.svg


def test_regression_1(built_html_path: Path) -> None:
Expand Down

0 comments on commit eb35b66

Please sign in to comment.