Skip to content

Commit 9135a21

Browse files
linawolfjaapio
authored andcommitted
[BUGFIX] Allow hyperlinks to anchors
Sphinx also allows them
1 parent 6610fde commit 9135a21

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

packages/guides/src/ReferenceResolvers/ExternalReferenceResolver.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use function parse_url;
1111
use function preg_match;
12+
use function str_starts_with;
1213

1314
use const PHP_URL_SCHEME;
1415

@@ -27,6 +28,12 @@ class ExternalReferenceResolver implements ReferenceResolver
2728

2829
public function resolve(LinkInlineNode $node, RenderContext $renderContext): bool
2930
{
31+
if (str_starts_with($node->getTargetReference(), '#')) {
32+
$node->setUrl($node->getTargetReference());
33+
34+
return true;
35+
}
36+
3037
$url = parse_url($node->getTargetReference(), PHP_URL_SCHEME);
3138
if ($url !== null && $url !== false && preg_match('/^' . self::SUPPORTED_SCHEMAS . '$/', $url)) {
3239
$node->setUrl($node->getTargetReference());
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Some file</title>
5+
6+
</head>
7+
<body>
8+
<div class="section" id="some-file">
9+
<h1>Some file</h1>
10+
11+
12+
13+
<ul>
14+
<li><a href="#">link to myself</a></li>
15+
16+
<li><a href="#abc">link to some anchor</a></li>
17+
18+
</ul>
19+
20+
</div>
21+
22+
</body>
23+
</html>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Some file
2+
=========
3+
4+
* `link to myself <#>`__
5+
6+
* `link to some anchor <#abc>`__

0 commit comments

Comments
 (0)