Skip to content

[BUGFIX] Fix interlink target URLs for links with anchor prefix #1175

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Nov 22, 2024
Merged
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
8 changes: 8 additions & 0 deletions packages/guides/src/Renderer/InterlinkObjectsRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace phpDocumentor\Guides\Renderer;

use phpDocumentor\Guides\Handlers\RenderCommand;
use phpDocumentor\Guides\Meta\InternalTarget;
use phpDocumentor\Guides\ReferenceResolvers\DocumentNameResolverInterface;
use phpDocumentor\Guides\RenderContext;
use phpDocumentor\Guides\Renderer\UrlGenerator\UrlGeneratorInterface;
Expand Down Expand Up @@ -73,6 +74,13 @@ public function render(RenderCommand $renderCommand): void
'',
$this->urlGenerator->createFileUrl($context, $internalTarget->getDocumentPath(), $internalTarget->getAnchor()),
);
if ($internalTarget instanceof InternalTarget) {
$url = $this->documentNameResolver->canonicalUrl(
'',
$this->urlGenerator->createFileUrl($context, $internalTarget->getDocumentPath(), $internalTarget->getPrefix() . $internalTarget->getAnchor()),
);
}

$inventory[$linkType][$key] = [
$projectNode->getTitle() ?? '-',
$projectNode->getVersion() ?? '-',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
</ol>
</nav>
<!-- content start -->
<div class="section" id="another-page">

<div class="section" id="another-page">
<h1>Another Page</h1>

<p>Lorem Ipsum Dolor.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
</ol>
</nav>
<!-- content start -->
<div class="section" id="document-title">

<div class="section" id="document-title">
<h1>Document Title</h1>

<p>Lorem Ipsum Dolor.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
</ol>
</nav>
<!-- content start -->
<div class="section" id="some-page">

<div class="section" id="some-page">
<h1>Some Page</h1>

<p>Lorem Ipsum <code>Dolor</code>.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,70 @@
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<body>
<header class="">
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
</ul>
</div>
</div>
</nav>

<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container">

<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">

<ul class="navbar-nav me-auto mb-2 mb-lg-0">
</ul>

</div>
</div>
</nav>
</header>
<main id="main-content">
<div class="container">
<div class="container">
<div class="row">
<div class="col-lg-3">
<nav class="nav flex-column">
<ul class="menu-level-main">
</ul>
</nav>
<nav class="nav flex-column">
<ul class="menu-level-main">
</ul>
</nav>

</div>
<div class="col-lg-9">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Document Title</a></li>
</ol>
</nav>

<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Document Title</a></li>
</ol>
</nav>
<!-- content start -->
<div class="section" id="document-title">
<h1>Document Title</h1>
<p>Lorem Ipsum Dolor.</p>
</div>

<div class="section" id="document-title">
<h1>Document Title</h1>

<p>Lorem Ipsum Dolor.</p>

</div>
<!-- content end -->
</div>
</div>
</div>
</div>
</main>

<!-- Optional JavaScript; choose one of the two! -->

<!-- Option 1: Bootstrap Bundle with Popper -->
<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>

<!-- Option 2: Separate Popper and Bootstrap JS -->
<!--
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
<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>
-->
</body>
</html>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@
</ol>
</nav>
<!-- content start -->
<div class="section" id="dir-2-title">

<div class="section" id="dir-2-title">
<h1>Dir 2 Title</h1>

<p>Lorem Ipsum Dolor.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@
</ol>
</nav>
<!-- content start -->
<div class="section" id="some-page-in-dir-2">

<div class="section" id="some-page-in-dir-2">
<h1>Some Page in dir 2</h1>

<p>Lorem Ipsum <code>Dolor</code>.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@
</ol>
</nav>
<!-- content start -->
<div class="section" id="document-title">

<div class="section" id="document-title">
<h1>Document Title</h1>

<p>Lorem Ipsum Dolor.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@
</ol>
</nav>
<!-- content start -->
<div class="section" id="dir-2-title">

<div class="section" id="dir-2-title">
<h1>Dir 2 Title</h1>

<p>Lorem Ipsum Dolor.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@
</ol>
</nav>
<!-- content start -->
<div class="section" id="some-page-in-dir-2">

<div class="section" id="some-page-in-dir-2">
<h1>Some Page in dir 2</h1>

<p>Lorem Ipsum <code>Dolor</code>.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@
</ol>
</nav>
<!-- content start -->
<div class="section" id="document-title">

<div class="section" id="document-title">
<h1>Document Title</h1>

<p>Lorem Ipsum Dolor.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,37 @@
"another-demo": [
"-",
"-",
"another.html#another-demo",
"another.html#confval-another-demo",
"demo"
],
"demo": [
"-",
"-",
"index.html#demo",
"index.html#confval-demo",
"demo"
],
"demo2": [
"-",
"-",
"index.html#demo2",
"index.html#confval-demo2",
"demo2"
],
"demo3": [
"-",
"-",
"index.html#demo3",
"index.html#confval-demo3",
"demo3"
],
"demo4": [
"-",
"-",
"index.html#demo4",
"index.html#confval-demo4",
"demo4"
],
"demo5": [
"-",
"-",
"index.html#demo5",
"index.html#confval-demo5",
"demo5"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"demo": [
"-",
"-",
"index.html#demo",
"index.html#confval-demo",
"demo"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"demo": [
"-",
"-",
"another.html#demo",
"another.html#confval-demo",
"demo"
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!-- content start -->
<div class="section" id="markdown-admonitions">

<div class="section" id="markdown-admonitions">
<h1>Markdown Admonitions</h1>
<div class="alert alert-secondary " role="alert">
<h4 class="alert-heading">Note</h4>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!-- content start -->
<div class="section" id="markdown-blockquotes">

<div class="section" id="markdown-blockquotes">
<h1>Markdown Blockquotes</h1>
<blockquote>
<p>This is a blockquote. It can span multiple lines.</p>
Expand Down
3 changes: 2 additions & 1 deletion tests/Integration/tests/markdown/code-md/expected/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!-- content start -->
<div class="section" id="markdown-with-code-blocks">

<div class="section" id="markdown-with-code-blocks">
<h1>Markdown with Code Blocks</h1>
<pre><code class="language-">&lt;html&gt;
&lt;head&gt;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<!-- content start -->
<div class="section" id="markdown-with-emphasis">

<div class="section" id="markdown-with-emphasis">
<h1>Markdown with emphasis</h1>

<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>


<p><a href="https://phpdoc.org"><em>test</em></a></p>

</div>
<!-- content end -->
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!-- content start -->
<div class="section" id="markdown-with-html">

<div class="section" id="markdown-with-html">
<h1>Markdown with html</h1>

<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>
Expand Down
3 changes: 2 additions & 1 deletion tests/Integration/tests/markdown/html-md/expected/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!-- content start -->
<div class="section" id="markdown-with-html">

<div class="section" id="markdown-with-html">
<h1>Markdown with html</h1>

<p>&lt;div align=&quot;center&quot;&gt;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!-- content start -->
<div class="section" id="images-with-and-without-alt-text">

<div class="section" id="images-with-and-without-alt-text">
<h1>Images with and without alt text</h1>

<p><img src="https://example.org/example.png" alt="with alt Text"/></p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!-- content start -->
<div class="section" id="markdown-image">

<div class="section" id="markdown-image">
<h1>Markdown Image</h1>

<p><img src="/hero-illustration.svg" alt="Hero Illustrations"/></p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!-- content start -->
<div class="section" id="dir-2-title">

<div class="section" id="dir-2-title">
<h1>Dir 2 Title</h1>

<p>Lorem Ipsum Dolor.</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!-- content start -->
<div class="section" id="some-page-in-dir-2">

<div class="section" id="some-page-in-dir-2">
<h1>Some Page in dir 2</h1>

<p>Lorem Ipsum <code>Dolor</code>.</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!-- content start -->
<div class="section" id="dir-1-title">

<div class="section" id="dir-1-title">
<h1>Dir 1 Title</h1>

<p>Lorem Ipsum Dolor.</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!-- content start -->
<div class="section" id="document-title">

<div class="section" id="document-title">
<h1>Document Title</h1>

<p>Lorem Ipsum Dolor.</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!-- content start -->
<div class="section" id="markdown-image">

<div class="section" id="markdown-image">
<h1>Markdown Image</h1>

<p><img src="/hero-illustration.svg" alt="Hero Illustrations" title="Some title"/></p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!-- content start -->
<div class="section" id="markdown-example">

<div class="section" id="markdown-example">
<h1>Markdown Example</h1>

<p>This is a Markdown document with some basic formatting.</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!-- content start -->
<div class="section" id="another-page">

<div class="section" id="another-page">
<h1>Another Page</h1>

<p>Lorem Ipsum Dolor.</p>
Expand Down
Loading
Loading