Skip to content

Commit c83bbd6

Browse files
authored
Merge pull request #1463 from ehuss/fix-header-scroll
Fix some issues with fragment scrolling and linking.
2 parents fad3c66 + 45d41ea commit c83bbd6

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

src/renderer/html_handlebars/hbs_renderer.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ fn insert_link_into_header(
756756
*id_count += 1;
757757

758758
format!(
759-
r##"<h{level}><a class="header" href="#{id}" id="{id}">{text}</a></h{level}>"##,
759+
r##"<h{level} id="{id}"><a class="header" href="#{id}">{text}</a></h{level}>"##,
760760
level = level,
761761
id = id,
762762
text = content
@@ -927,27 +927,27 @@ mod tests {
927927
let inputs = vec![
928928
(
929929
"blah blah <h1>Foo</h1>",
930-
r##"blah blah <h1><a class="header" href="#foo" id="foo">Foo</a></h1>"##,
930+
r##"blah blah <h1 id="foo"><a class="header" href="#foo">Foo</a></h1>"##,
931931
),
932932
(
933933
"<h1>Foo</h1>",
934-
r##"<h1><a class="header" href="#foo" id="foo">Foo</a></h1>"##,
934+
r##"<h1 id="foo"><a class="header" href="#foo">Foo</a></h1>"##,
935935
),
936936
(
937937
"<h3>Foo^bar</h3>",
938-
r##"<h3><a class="header" href="#foobar" id="foobar">Foo^bar</a></h3>"##,
938+
r##"<h3 id="foobar"><a class="header" href="#foobar">Foo^bar</a></h3>"##,
939939
),
940940
(
941941
"<h4></h4>",
942-
r##"<h4><a class="header" href="#" id=""></a></h4>"##,
942+
r##"<h4 id=""><a class="header" href="#"></a></h4>"##,
943943
),
944944
(
945945
"<h4><em>Hï</em></h4>",
946-
r##"<h4><a class="header" href="#hï" id="hï"><em>Hï</em></a></h4>"##,
946+
r##"<h4 id="hï"><a class="header" href="#hï"><em>Hï</em></a></h4>"##,
947947
),
948948
(
949949
"<h1>Foo</h1><h3>Foo</h3>",
950-
r##"<h1><a class="header" href="#foo" id="foo">Foo</a></h1><h3><a class="header" href="#foo-1" id="foo-1">Foo</a></h3>"##,
950+
r##"<h1 id="foo"><a class="header" href="#foo">Foo</a></h1><h3 id="foo-1"><a class="header" href="#foo-1">Foo</a></h3>"##,
951951
),
952952
];
953953

src/theme/css/general.css

+11-8
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,23 @@ h4, h5 { margin-top: 2em; }
4545
margin-top: 1em;
4646
}
4747

48-
h1 a.header:target::before,
49-
h2 a.header:target::before,
50-
h3 a.header:target::before,
51-
h4 a.header:target::before {
48+
h1:target::before,
49+
h2:target::before,
50+
h3:target::before,
51+
h4:target::before,
52+
h5:target::before,
53+
h6:target::before {
5254
display: inline-block;
5355
content: "»";
5456
margin-left: -30px;
5557
width: 30px;
5658
}
5759

58-
h1 a.header:target,
59-
h2 a.header:target,
60-
h3 a.header:target,
61-
h4 a.header:target {
60+
/* This is broken on Safari as of version 14, but is fixed
61+
in Safari Technology Preview 117 which I think will be Safari 14.2.
62+
https://bugs.webkit.org/show_bug.cgi?id=218076
63+
*/
64+
:target {
6265
scroll-margin-top: calc(var(--menu-bar-height) + 0.5em);
6366
}
6467

tests/rendered_output.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ fn check_correct_cross_links_in_nested_dir() {
104104

105105
assert_contains_strings(
106106
first.join("index.html"),
107-
&[r##"href="#some-section" id="some-section""##],
107+
&[r##"<h2 id="some-section"><a class="header" href="#some-section">"##],
108108
);
109109

110110
assert_contains_strings(
111111
first.join("nested.html"),
112-
&[r##"href="#some-section" id="some-section""##],
112+
&[r##"<h2 id="some-section"><a class="header" href="#some-section">"##],
113113
);
114114
}
115115

@@ -373,7 +373,7 @@ fn able_to_include_files_in_chapters() {
373373
let includes = temp.path().join("book/first/includes.html");
374374

375375
let summary_strings = &[
376-
r##"<h1><a class="header" href="#summary" id="summary">Summary</a></h1>"##,
376+
r##"<h1 id="summary"><a class="header" href="#summary">Summary</a></h1>"##,
377377
">First Chapter</a>",
378378
];
379379
assert_contains_strings(&includes, summary_strings);

0 commit comments

Comments
 (0)