File tree 4 files changed +20
-4
lines changed
4 files changed +20
-4
lines changed Original file line number Diff line number Diff line change 22
22
< a href ="#Upper-ÄÖö "> back to Upper-ÄÖö</ a > < br >
23
23
< a href ="#Upper-%C3%84%C3%96%C3%B6 "> back to öüä encoded</ a > < br >
24
24
< a href ="#in-the-end "> doesn't exist</ a > < br >
25
+ < a href ="# "> To the top</ a > < br >
26
+ < a href ="#top "> To the top alt</ a > < br >
25
27
</ section >
26
28
</ body >
27
29
</ html >
Original file line number Diff line number Diff line change @@ -54,4 +54,12 @@ Therefore we put the test into a code block for now to prevent false positives.
54
54
[ Link to umlauts wrong case] ( #fünf-sÜße-Äpfel )
55
55
[ Link to umlauts with percent encoding] ( #f%C3%BCnf-s%C3%BC%C3%9Fe-%C3%A4pfel )
56
56
57
+ # To top fragments
58
+
59
+ The empty "#" and "#top" fragments are always valid
60
+ without related HTML element. Browser will scroll to the top of the page.
61
+
62
+ [ Link to top of file2] ( file2.md# )
63
+ [ Alternative link to top of file2] ( file2.md#top )
64
+
57
65
##### Lets wear a hat: être
Original file line number Diff line number Diff line change @@ -1835,8 +1835,10 @@ mod cli {
1835
1835
. stderr ( contains (
1836
1836
"fixtures/fragments/file1.md#kebab-case-fragment-1" ,
1837
1837
) )
1838
- . stdout ( contains ( "21 Total" ) )
1839
- . stdout ( contains ( "17 OK" ) )
1838
+ . stderr ( contains ( "fixtures/fragments/file.html#top" ) )
1839
+ . stderr ( contains ( "fixtures/fragments/file2.md#top" ) )
1840
+ . stdout ( contains ( "25 Total" ) )
1841
+ . stdout ( contains ( "21 OK" ) )
1840
1842
// 4 failures because of missing fragments
1841
1843
. stdout ( contains ( "4 Errors" ) ) ;
1842
1844
}
Original file line number Diff line number Diff line change @@ -39,14 +39,18 @@ impl FragmentChecker {
39
39
40
40
/// Checks if the given path contains the given fragment.
41
41
///
42
- /// Returns false, if there is a fragment in the link and the path is to a
43
- /// Markdown file, which doesn't contain the given fragment.
42
+ /// Returns false, if there is a fragment in the link which is not empty or "top"
43
+ /// and the path is to a Markdown file, which doesn't contain the given fragment.
44
+ /// (Empty # and #top fragments are always valid, triggering the browser to scroll to top.)
44
45
///
45
46
/// In all other cases, returns true.
46
47
pub ( crate ) async fn check ( & self , path : & Path , url : & Url ) -> Result < bool > {
47
48
let Some ( fragment) = url. fragment ( ) else {
48
49
return Ok ( true ) ;
49
50
} ;
51
+ if fragment. is_empty ( ) || fragment. eq_ignore_ascii_case ( "top" ) {
52
+ return Ok ( true ) ;
53
+ } ;
50
54
let mut fragment_decoded = percent_decode_str ( fragment) . decode_utf8 ( ) ?;
51
55
let url_without_frag = Self :: remove_fragment ( url. clone ( ) ) ;
52
56
You can’t perform that action at this time.
0 commit comments