From cfc37353fe9c6d1e5443e51258245549a9f781fb Mon Sep 17 00:00:00 2001 From: ftnext Date: Thu, 27 Jun 2024 21:51:39 +0900 Subject: [PATCH] [feat] Add fixed size external-link octicon --- src/sphinx_new_tab_link/__init__.py | 11 +++++++++-- tests/test_show_external_link_icon.py | 8 +++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/sphinx_new_tab_link/__init__.py b/src/sphinx_new_tab_link/__init__.py index a65a33b..a09f354 100644 --- a/src/sphinx_new_tab_link/__init__.py +++ b/src/sphinx_new_tab_link/__init__.py @@ -1,6 +1,6 @@ from typing import TypedDict -from docutils.nodes import Text +from docutils.nodes import Text, raw from sphinx.application import Sphinx from sphinxcontrib.kasane import new_translator_class_for_builder @@ -25,7 +25,14 @@ def starttag(self, node, tagname, *args, **atts): atts["target"] = "_blank" atts["rel"] = "noopener noreferrer" if self.builder.config.new_tab_link_show_external_link_icon: - node[0] = Text(node[0].astext() + " (external link icon)") + node[0] = Text(node[0].astext() + " ") + node.append( + raw( + # https://primer.style/foundations/icons/link-external-16/ + text='', + format="html", + ) + ) return super().starttag(node, tagname, *args, **atts) diff --git a/tests/test_show_external_link_icon.py b/tests/test_show_external_link_icon.py index 87ecdbf..dd7a370 100644 --- a/tests/test_show_external_link_icon.py +++ b/tests/test_show_external_link_icon.py @@ -9,7 +9,7 @@ def test_see_external_link_icon( sphinx_test_tempdir: Path, rootdir: Path, ): - srcdir = sphinx_test_tempdir / "test-external-link-icon" + srcdir = sphinx_test_tempdir / "external-link-icon" if not srcdir.exists(): testroot_path = rootdir / "test-external-link-icon" shutil.copytree(testroot_path, srcdir) @@ -22,10 +22,8 @@ def test_see_external_link_icon( references = soup.find_all("a", {"class": "reference"}) ref = references[0] - assert ( - ref.text - == "https://pypi.org/project/sphinx-new-tab-link/ (external link icon)" - ) + assert ref.text == "https://pypi.org/project/sphinx-new-tab-link/ " + assert ref.svg assert ref["href"] == "https://pypi.org/project/sphinx-new-tab-link/" assert ref["target"] == "_blank" assert ref["rel"] == ["noopener", "noreferrer"]