Skip to content

Commit b17a352

Browse files
authored
Merge pull request #1175 from phpDocumentor/bugfix/interlink-prefix
[BUGFIX] Fix interlink target URLs for links with anchor prefix
2 parents 3ceb2cf + a821ca9 commit b17a352

File tree

40 files changed

+128
-69
lines changed

40 files changed

+128
-69
lines changed

packages/guides/src/Renderer/InterlinkObjectsRenderer.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace phpDocumentor\Guides\Renderer;
1515

1616
use phpDocumentor\Guides\Handlers\RenderCommand;
17+
use phpDocumentor\Guides\Meta\InternalTarget;
1718
use phpDocumentor\Guides\ReferenceResolvers\DocumentNameResolverInterface;
1819
use phpDocumentor\Guides\RenderContext;
1920
use phpDocumentor\Guides\Renderer\UrlGenerator\UrlGeneratorInterface;
@@ -73,6 +74,13 @@ public function render(RenderCommand $renderCommand): void
7374
'',
7475
$this->urlGenerator->createFileUrl($context, $internalTarget->getDocumentPath(), $internalTarget->getAnchor()),
7576
);
77+
if ($internalTarget instanceof InternalTarget) {
78+
$url = $this->documentNameResolver->canonicalUrl(
79+
'',
80+
$this->urlGenerator->createFileUrl($context, $internalTarget->getDocumentPath(), $internalTarget->getPrefix() . $internalTarget->getAnchor()),
81+
);
82+
}
83+
7684
$inventory[$linkType][$key] = [
7785
$projectNode->getTitle() ?? '-',
7886
$projectNode->getVersion() ?? '-',

tests/Integration/tests-full/markdown-full/default-menu-md/expected/anotherPage.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
</ol>
7272
</nav>
7373
<!-- content start -->
74-
<div class="section" id="another-page">
74+
75+
<div class="section" id="another-page">
7576
<h1>Another Page</h1>
7677

7778
<p>Lorem Ipsum Dolor.</p>

tests/Integration/tests-full/markdown-full/default-menu-md/expected/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@
7070
</ol>
7171
</nav>
7272
<!-- content start -->
73-
<div class="section" id="document-title">
73+
74+
<div class="section" id="document-title">
7475
<h1>Document Title</h1>
7576

7677
<p>Lorem Ipsum Dolor.</p>

tests/Integration/tests-full/markdown-full/default-menu-md/expected/somePage.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
</ol>
7272
</nav>
7373
<!-- content start -->
74-
<div class="section" id="some-page">
74+
75+
<div class="section" id="some-page">
7576
<h1>Some Page</h1>
7677

7778
<p>Lorem Ipsum <code>Dolor</code>.</p>

tests/Integration/tests-full/markdown-full/front-matter-md/expected/index.html

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,70 @@
55
<!-- Required meta tags -->
66
<meta charset="utf-8">
77
<meta name="viewport" content="width=device-width, initial-scale=1">
8+
89
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
910
</head>
1011
<body>
1112
<header class="">
12-
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
13-
<div class="container">
14-
<a class="navbar-brand" href="#">Navbar</a>
15-
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
16-
<span class="navbar-toggler-icon"></span>
17-
</button>
18-
<div class="collapse navbar-collapse" id="navbarSupportedContent">
19-
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
20-
</ul>
21-
</div>
22-
</div>
23-
</nav>
13+
14+
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
15+
<div class="container">
16+
17+
<a class="navbar-brand" href="#">Navbar</a>
18+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
19+
<span class="navbar-toggler-icon"></span>
20+
</button>
21+
<div class="collapse navbar-collapse" id="navbarSupportedContent">
22+
23+
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
24+
</ul>
25+
26+
</div>
27+
</div>
28+
</nav>
2429
</header>
2530
<main id="main-content">
2631
<div class="container">
2732
<div class="container">
2833
<div class="row">
2934
<div class="col-lg-3">
30-
<nav class="nav flex-column">
31-
<ul class="menu-level-main">
32-
</ul>
33-
</nav>
35+
<nav class="nav flex-column">
36+
<ul class="menu-level-main">
37+
</ul>
38+
</nav>
39+
3440
</div>
3541
<div class="col-lg-9">
36-
<nav aria-label="breadcrumb">
37-
<ol class="breadcrumb">
38-
<li class="breadcrumb-item"><a href="#">Document Title</a></li>
39-
</ol>
40-
</nav>
42+
43+
<nav aria-label="breadcrumb">
44+
<ol class="breadcrumb">
45+
<li class="breadcrumb-item"><a href="#">Document Title</a></li>
46+
</ol>
47+
</nav>
4148
<!-- content start -->
42-
<div class="section" id="document-title">
43-
<h1>Document Title</h1>
44-
<p>Lorem Ipsum Dolor.</p>
45-
</div>
49+
50+
<div class="section" id="document-title">
51+
<h1>Document Title</h1>
52+
53+
<p>Lorem Ipsum Dolor.</p>
54+
55+
</div>
4656
<!-- content end -->
4757
</div>
4858
</div>
4959
</div>
5060
</div>
5161
</main>
62+
5263
<!-- Optional JavaScript; choose one of the two! -->
64+
5365
<!-- Option 1: Bootstrap Bundle with Popper -->
5466
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
67+
5568
<!-- Option 2: Separate Popper and Bootstrap JS -->
5669
<!--
5770
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
5871
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
5972
-->
6073
</body>
61-
</html>
74+
</html>

tests/Integration/tests-full/markdown-full/multi-nested-menu-md/expected/dir2/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@
140140
</ol>
141141
</nav>
142142
<!-- content start -->
143-
<div class="section" id="dir-2-title">
143+
144+
<div class="section" id="dir-2-title">
144145
<h1>Dir 2 Title</h1>
145146

146147
<p>Lorem Ipsum Dolor.</p>

tests/Integration/tests-full/markdown-full/multi-nested-menu-md/expected/dir2/somePage.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@
141141
</ol>
142142
</nav>
143143
<!-- content start -->
144-
<div class="section" id="some-page-in-dir-2">
144+
145+
<div class="section" id="some-page-in-dir-2">
145146
<h1>Some Page in dir 2</h1>
146147

147148
<p>Lorem Ipsum <code>Dolor</code>.</p>

tests/Integration/tests-full/markdown-full/multi-nested-menu-md/expected/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@
139139
</ol>
140140
</nav>
141141
<!-- content start -->
142-
<div class="section" id="document-title">
142+
143+
<div class="section" id="document-title">
143144
<h1>Document Title</h1>
144145

145146
<p>Lorem Ipsum Dolor.</p>

tests/Integration/tests-full/markdown-full/nested-menu-md/expected/dir2/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@
117117
</ol>
118118
</nav>
119119
<!-- content start -->
120-
<div class="section" id="dir-2-title">
120+
121+
<div class="section" id="dir-2-title">
121122
<h1>Dir 2 Title</h1>
122123

123124
<p>Lorem Ipsum Dolor.</p>

tests/Integration/tests-full/markdown-full/nested-menu-md/expected/dir2/somePage.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@
118118
</ol>
119119
</nav>
120120
<!-- content start -->
121-
<div class="section" id="some-page-in-dir-2">
121+
122+
<div class="section" id="some-page-in-dir-2">
122123
<h1>Some Page in dir 2</h1>
123124

124125
<p>Lorem Ipsum <code>Dolor</code>.</p>

tests/Integration/tests-full/markdown-full/nested-menu-md/expected/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@
116116
</ol>
117117
</nav>
118118
<!-- content start -->
119-
<div class="section" id="document-title">
119+
120+
<div class="section" id="document-title">
120121
<h1>Document Title</h1>
121122

122123
<p>Lorem Ipsum Dolor.</p>

tests/Integration/tests/confval/confval-name/expected/objects.inv.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,37 @@
2626
"another-demo": [
2727
"-",
2828
"-",
29-
"another.html#another-demo",
29+
"another.html#confval-another-demo",
3030
"demo"
3131
],
3232
"demo": [
3333
"-",
3434
"-",
35-
"index.html#demo",
35+
"index.html#confval-demo",
3636
"demo"
3737
],
3838
"demo2": [
3939
"-",
4040
"-",
41-
"index.html#demo2",
41+
"index.html#confval-demo2",
4242
"demo2"
4343
],
4444
"demo3": [
4545
"-",
4646
"-",
47-
"index.html#demo3",
47+
"index.html#confval-demo3",
4848
"demo3"
4949
],
5050
"demo4": [
5151
"-",
5252
"-",
53-
"index.html#demo4",
53+
"index.html#confval-demo4",
5454
"demo4"
5555
],
5656
"demo5": [
5757
"-",
5858
"-",
59-
"index.html#demo5",
59+
"index.html#confval-demo5",
6060
"demo5"
6161
]
6262
}

tests/Integration/tests/confval/confval-noindex/expected/objects.inv.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"demo": [
2727
"-",
2828
"-",
29-
"index.html#demo",
29+
"index.html#confval-demo",
3030
"demo"
3131
]
3232
}

tests/Integration/tests/confval/confval-warning/expected/objects.inv.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"demo": [
3434
"-",
3535
"-",
36-
"another.html#demo",
36+
"another.html#confval-demo",
3737
"demo"
3838
]
3939
}

tests/Integration/tests/markdown/admonitions-md/expected/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!-- content start -->
2-
<div class="section" id="markdown-admonitions">
2+
3+
<div class="section" id="markdown-admonitions">
34
<h1>Markdown Admonitions</h1>
45
<div class="alert alert-secondary " role="alert">
56
<h4 class="alert-heading">Note</h4>

tests/Integration/tests/markdown/blockquote-md/expected/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!-- content start -->
2-
<div class="section" id="markdown-blockquotes">
2+
3+
<div class="section" id="markdown-blockquotes">
34
<h1>Markdown Blockquotes</h1>
45
<blockquote>
56
<p>This is a blockquote. It can span multiple lines.</p>

tests/Integration/tests/markdown/code-md/expected/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!-- content start -->
2-
<div class="section" id="markdown-with-code-blocks">
2+
3+
<div class="section" id="markdown-with-code-blocks">
34
<h1>Markdown with Code Blocks</h1>
45
<pre><code class="language-">&lt;html&gt;
56
&lt;head&gt;
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<!-- content start -->
2-
<div class="section" id="markdown-with-emphasis">
2+
3+
<div class="section" id="markdown-with-emphasis">
34
<h1>Markdown with emphasis</h1>
45

56
<p><em>Italic</em> or <em>Italic</em>, <strong>Bold</strong> or <strong>Bold</strong>, <strong>Bold and <em>Italic</em></strong>, <em>Italic and <strong>Bold</strong></em></p>
7+
8+
69
<p><a href="https://phpdoc.org"><em>test</em></a></p>
10+
711
</div>
812
<!-- content end -->

tests/Integration/tests/markdown/html-inline-md/expected/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!-- content start -->
2-
<div class="section" id="markdown-with-html">
2+
3+
<div class="section" id="markdown-with-html">
34
<h1>Markdown with html</h1>
45

56
<p>In files of text, where words take flight, Markdown weaves its magic, bold and bright. Hashes and stars, a simple code, A poet&#039;s playground, where stories unfold. &lt;BR&gt;</p>

tests/Integration/tests/markdown/html-md/expected/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!-- content start -->
2-
<div class="section" id="markdown-with-html">
2+
3+
<div class="section" id="markdown-with-html">
34
<h1>Markdown with html</h1>
45

56
<p>&lt;div align=&quot;center&quot;&gt;

tests/Integration/tests/markdown/image-empty-alt-md/expected/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!-- content start -->
2-
<div class="section" id="images-with-and-without-alt-text">
2+
3+
<div class="section" id="images-with-and-without-alt-text">
34
<h1>Images with and without alt text</h1>
45

56
<p><img src="https://example.org/example.png" alt="with alt Text"/></p>

tests/Integration/tests/markdown/image-md/expected/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!-- content start -->
2-
<div class="section" id="markdown-image">
2+
3+
<div class="section" id="markdown-image">
34
<h1>Markdown Image</h1>
45

56
<p><img src="/hero-illustration.svg" alt="Hero Illustrations"/></p>

tests/Integration/tests/markdown/image-path-relative-md/expected/dir1/dir2/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!-- content start -->
2-
<div class="section" id="dir-2-title">
2+
3+
<div class="section" id="dir-2-title">
34
<h1>Dir 2 Title</h1>
45

56
<p>Lorem Ipsum Dolor.</p>

tests/Integration/tests/markdown/image-path-relative-md/expected/dir1/dir2/somePage.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!-- content start -->
2-
<div class="section" id="some-page-in-dir-2">
2+
3+
<div class="section" id="some-page-in-dir-2">
34
<h1>Some Page in dir 2</h1>
45

56
<p>Lorem Ipsum <code>Dolor</code>.</p>

tests/Integration/tests/markdown/image-path-relative-md/expected/dir1/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!-- content start -->
2-
<div class="section" id="dir-1-title">
2+
3+
<div class="section" id="dir-1-title">
34
<h1>Dir 1 Title</h1>
45

56
<p>Lorem Ipsum Dolor.</p>

tests/Integration/tests/markdown/image-path-relative-md/expected/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!-- content start -->
2-
<div class="section" id="document-title">
2+
3+
<div class="section" id="document-title">
34
<h1>Document Title</h1>
45

56
<p>Lorem Ipsum Dolor.</p>

tests/Integration/tests/markdown/image-title-md/expected/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!-- content start -->
2-
<div class="section" id="markdown-image">
2+
3+
<div class="section" id="markdown-image">
34
<h1>Markdown Image</h1>
45

56
<p><img src="/hero-illustration.svg" alt="Hero Illustrations" title="Some title"/></p>

tests/Integration/tests/markdown/index-md/expected/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!-- content start -->
2-
<div class="section" id="markdown-example">
2+
3+
<div class="section" id="markdown-example">
34
<h1>Markdown Example</h1>
45

56
<p>This is a Markdown document with some basic formatting.</p>

tests/Integration/tests/markdown/index-name-md/expected/anotherPage.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!-- content start -->
2-
<div class="section" id="another-page">
2+
3+
<div class="section" id="another-page">
34
<h1>Another Page</h1>
45

56
<p>Lorem Ipsum Dolor.</p>

0 commit comments

Comments
 (0)