File tree 4 files changed +20
-7
lines changed
4 files changed +20
-7
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 @@ -1834,8 +1834,10 @@ mod cli {
1834
1834
. stderr ( contains (
1835
1835
"fixtures/fragments/file1.md#kebab-case-fragment-1" ,
1836
1836
) )
1837
- . stdout ( contains ( "21 Total" ) )
1838
- . stdout ( contains ( "17 OK" ) )
1837
+ . stderr ( contains ( "fixtures/fragments/file.html#top" ) )
1838
+ . stderr ( contains ( "fixtures/fragments/file2.md#top" ) )
1839
+ . stdout ( contains ( "25 Total" ) )
1840
+ . stdout ( contains ( "21 OK" ) )
1839
1841
// 4 failures because of missing fragments
1840
1842
. stdout ( contains ( "4 Errors" ) ) ;
1841
1843
}
Original file line number Diff line number Diff line change @@ -59,19 +59,20 @@ impl FragmentChecker {
59
59
if file_type == FileType :: Markdown {
60
60
fragment_decoded = fragment_decoded. to_lowercase ( ) . into ( ) ;
61
61
}
62
+ // Empty # and #top fragments are always valid, triggering the browser to scroll to top.
63
+ let is_emtpty_or_top_fragment = fragment. is_empty ( ) || fragment. eq_ignore_ascii_case ( "top" ) ;
62
64
match self . cache . lock ( ) . await . entry ( url_without_frag) {
63
65
Entry :: Vacant ( entry) => {
64
66
let content = fs:: read_to_string ( path) . await ?;
65
67
let file_frags = extractor ( & content) ;
66
68
let contains_fragment =
67
69
file_frags. contains ( fragment) || file_frags. contains ( & fragment_decoded as & str ) ;
68
70
entry. insert ( file_frags) ;
69
- Ok ( contains_fragment)
70
- }
71
- Entry :: Occupied ( entry) => {
72
- Ok ( entry. get ( ) . contains ( fragment)
73
- || entry. get ( ) . contains ( & fragment_decoded as & str ) )
71
+ Ok ( is_emtpty_or_top_fragment || contains_fragment)
74
72
}
73
+ Entry :: Occupied ( entry) => Ok ( is_emtpty_or_top_fragment
74
+ || entry. get ( ) . contains ( fragment)
75
+ || entry. get ( ) . contains ( & fragment_decoded as & str ) ) ,
75
76
}
76
77
}
77
78
You can’t perform that action at this time.
0 commit comments