Skip to content

Commit

Permalink
Merge pull request #206 from daizutabi/205-correct-link-title
Browse files Browse the repository at this point in the history
Correct link title
  • Loading branch information
daizutabi committed Sep 23, 2024
2 parents 8279d34 + f92d221 commit 13bac09
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/mkapi/css/mkapi-common.css
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,15 @@ ul.mkapi-item-list {
.mkapi-object-link {
font-size: 0.85em;
margin-left: 1.2em;
vertical-align: baseline;
}

.mkapi-document-toggle,
.mkapi-parent-toggle,
.mkapi-section-toggle {
.mkapi-section-toggle,
.mkapi-definition-link {
cursor: pointer;
color: var(--mkapi-punctuation-color);
font-size: 0.85em;
}

.mkapi-document-toggle:hover,
Expand Down
4 changes: 3 additions & 1 deletion src/mkapi/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def _link(match: re.Match, src_uri: str, namespace: str) -> str:
asname = ""

if m := OBJECT_LINK_PATTERN.match(fullname):
is_object_link = True
namespace, fullname = m.groups()

if namespace == "definition" and "object" in URIS:
Expand All @@ -188,6 +189,7 @@ def _link(match: re.Match, src_uri: str, namespace: str) -> str:
return ""

else:
is_object_link = False
asname = match.group()

if fullname.startswith("__mkapi__."):
Expand All @@ -199,7 +201,7 @@ def _link(match: re.Match, src_uri: str, namespace: str) -> str:
if uri := URIS[namespace].get(fullname):
uri = os.path.relpath(uri, PurePath(src_uri).parent)
uri = uri.replace("\\", "/") # Normalize for Windows
title = ANCHOR_TITLES[namespace]
title = ANCHOR_TITLES[namespace] if is_object_link else fullname
return f'[{name}]({uri}#{fullname} "{title}")'

if from_mkapi and name != ANCHOR_PLACEHOLDERS["definition"]:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def test_link_not_from_mkapi():
m = LINK_PATTERN.match("[A][x.y]")
assert m
m = _link(m, "y/a.md", "definition")
assert m == '[A](../z/a/c.md#x.y "Go to definition")'
assert m == '[A](../z/a/c.md#x.y "x.y")'


def test_link_not_from_mkapi_invalid():
Expand All @@ -164,7 +164,7 @@ def test_link_backticks():
m = LINK_PATTERN.match("[`A`][x.y]")
assert m
m = _link(m, "q/r/a.md", "source")
assert m == '[`A`](../../p/B.md#x.y "Go to source")'
assert m == '[`A`](../../p/B.md#x.y "x.y")'


def test_link_without_fullname():
Expand All @@ -174,7 +174,7 @@ def test_link_without_fullname():
m = LINK_PATTERN.match("[x.y][]")
assert m
m = _link(m, "q/r/a.md", "object")
assert m == '[x.y](a.md#x.y "Go to docs")'
assert m == '[x.y](a.md#x.y "x.y")'


def test_link_without_fullname_backticks():
Expand All @@ -184,7 +184,7 @@ def test_link_without_fullname_backticks():
m = LINK_PATTERN.match("[`x.y`][]")
assert m
m = _link(m, "q/r/a.md", "source")
assert m == '[`x.y`](../s/a.md#x.y "Go to source")'
assert m == '[`x.y`](../s/a.md#x.y "x.y")'


def test_page_convert_object_page():
Expand Down

0 comments on commit 13bac09

Please sign in to comment.