File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed
packages/guides/src/ReferenceResolvers
tests/Integration/tests/hyperlink-to-anchor Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 99
1010use function parse_url ;
1111use function preg_match ;
12+ use function str_starts_with ;
1213
1314use 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 ());
Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 1+ Some file
2+ =========
3+
4+ * `link to myself <# >`__
5+
6+ * `link to some anchor <#abc >`__
You can’t perform that action at this time.
0 commit comments