Fix some issues with fragment scrolling and linking.
This commit is contained in:
parent
0b9570b160
commit
45d41eac5f
|
@ -756,7 +756,7 @@ fn insert_link_into_header(
|
||||||
*id_count += 1;
|
*id_count += 1;
|
||||||
|
|
||||||
format!(
|
format!(
|
||||||
r##"<h{level}><a class="header" href="#{id}" id="{id}">{text}</a></h{level}>"##,
|
r##"<h{level} id="{id}"><a class="header" href="#{id}">{text}</a></h{level}>"##,
|
||||||
level = level,
|
level = level,
|
||||||
id = id,
|
id = id,
|
||||||
text = content
|
text = content
|
||||||
|
@ -927,27 +927,27 @@ mod tests {
|
||||||
let inputs = vec![
|
let inputs = vec![
|
||||||
(
|
(
|
||||||
"blah blah <h1>Foo</h1>",
|
"blah blah <h1>Foo</h1>",
|
||||||
r##"blah blah <h1><a class="header" href="#foo" id="foo">Foo</a></h1>"##,
|
r##"blah blah <h1 id="foo"><a class="header" href="#foo">Foo</a></h1>"##,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"<h1>Foo</h1>",
|
"<h1>Foo</h1>",
|
||||||
r##"<h1><a class="header" href="#foo" id="foo">Foo</a></h1>"##,
|
r##"<h1 id="foo"><a class="header" href="#foo">Foo</a></h1>"##,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"<h3>Foo^bar</h3>",
|
"<h3>Foo^bar</h3>",
|
||||||
r##"<h3><a class="header" href="#foobar" id="foobar">Foo^bar</a></h3>"##,
|
r##"<h3 id="foobar"><a class="header" href="#foobar">Foo^bar</a></h3>"##,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"<h4></h4>",
|
"<h4></h4>",
|
||||||
r##"<h4><a class="header" href="#" id=""></a></h4>"##,
|
r##"<h4 id=""><a class="header" href="#"></a></h4>"##,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"<h4><em>Hï</em></h4>",
|
"<h4><em>Hï</em></h4>",
|
||||||
r##"<h4><a class="header" href="#hï" id="hï"><em>Hï</em></a></h4>"##,
|
r##"<h4 id="hï"><a class="header" href="#hï"><em>Hï</em></a></h4>"##,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"<h1>Foo</h1><h3>Foo</h3>",
|
"<h1>Foo</h1><h3>Foo</h3>",
|
||||||
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>"##,
|
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>"##,
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -45,20 +45,23 @@ h4, h5 { margin-top: 2em; }
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 a.header:target::before,
|
h1:target::before,
|
||||||
h2 a.header:target::before,
|
h2:target::before,
|
||||||
h3 a.header:target::before,
|
h3:target::before,
|
||||||
h4 a.header:target::before {
|
h4:target::before,
|
||||||
|
h5:target::before,
|
||||||
|
h6:target::before {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
content: "»";
|
content: "»";
|
||||||
margin-left: -30px;
|
margin-left: -30px;
|
||||||
width: 30px;
|
width: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 a.header:target,
|
/* This is broken on Safari as of version 14, but is fixed
|
||||||
h2 a.header:target,
|
in Safari Technology Preview 117 which I think will be Safari 14.2.
|
||||||
h3 a.header:target,
|
https://bugs.webkit.org/show_bug.cgi?id=218076
|
||||||
h4 a.header:target {
|
*/
|
||||||
|
:target {
|
||||||
scroll-margin-top: calc(var(--menu-bar-height) + 0.5em);
|
scroll-margin-top: calc(var(--menu-bar-height) + 0.5em);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,12 +104,12 @@ fn check_correct_cross_links_in_nested_dir() {
|
||||||
|
|
||||||
assert_contains_strings(
|
assert_contains_strings(
|
||||||
first.join("index.html"),
|
first.join("index.html"),
|
||||||
&[r##"href="#some-section" id="some-section""##],
|
&[r##"<h2 id="some-section"><a class="header" href="#some-section">"##],
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_contains_strings(
|
assert_contains_strings(
|
||||||
first.join("nested.html"),
|
first.join("nested.html"),
|
||||||
&[r##"href="#some-section" id="some-section""##],
|
&[r##"<h2 id="some-section"><a class="header" href="#some-section">"##],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,7 +373,7 @@ fn able_to_include_files_in_chapters() {
|
||||||
let includes = temp.path().join("book/first/includes.html");
|
let includes = temp.path().join("book/first/includes.html");
|
||||||
|
|
||||||
let summary_strings = &[
|
let summary_strings = &[
|
||||||
r##"<h1><a class="header" href="#summary" id="summary">Summary</a></h1>"##,
|
r##"<h1 id="summary"><a class="header" href="#summary">Summary</a></h1>"##,
|
||||||
">First Chapter</a>",
|
">First Chapter</a>",
|
||||||
];
|
];
|
||||||
assert_contains_strings(&includes, summary_strings);
|
assert_contains_strings(&includes, summary_strings);
|
||||||
|
|
Loading…
Reference in New Issue