From 45d41eac5f141c66af9589b56fe8d23f91fc7b22 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 12 Feb 2021 16:37:07 -0800 Subject: [PATCH] Fix some issues with fragment scrolling and linking. --- src/renderer/html_handlebars/hbs_renderer.rs | 14 +++++++------- src/theme/css/general.css | 19 +++++++++++-------- tests/rendered_output.rs | 6 +++--- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 6b934b13..66572d04 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -756,7 +756,7 @@ fn insert_link_into_header( *id_count += 1; format!( - r##"{text}"##, + r##"{text}"##, level = level, id = id, text = content @@ -927,27 +927,27 @@ mod tests { let inputs = vec![ ( "blah blah

Foo

", - r##"blah blah

Foo

"##, + r##"blah blah

Foo

"##, ), ( "

Foo

", - r##"

Foo

"##, + r##"

Foo

"##, ), ( "

Foo^bar

", - r##"

Foo^bar

"##, + r##"

Foo^bar

"##, ), ( "

", - r##"

"##, + r##"

"##, ), ( "

", - r##"

"##, + r##"

"##, ), ( "

Foo

Foo

", - r##"

Foo

Foo

"##, + r##"

Foo

Foo

"##, ), ]; diff --git a/src/theme/css/general.css b/src/theme/css/general.css index 815dae1a..d437b51c 100644 --- a/src/theme/css/general.css +++ b/src/theme/css/general.css @@ -45,20 +45,23 @@ h4, h5 { margin-top: 2em; } margin-top: 1em; } -h1 a.header:target::before, -h2 a.header:target::before, -h3 a.header:target::before, -h4 a.header:target::before { +h1:target::before, +h2:target::before, +h3:target::before, +h4:target::before, +h5:target::before, +h6:target::before { display: inline-block; content: "»"; margin-left: -30px; width: 30px; } -h1 a.header:target, -h2 a.header:target, -h3 a.header:target, -h4 a.header:target { +/* This is broken on Safari as of version 14, but is fixed + in Safari Technology Preview 117 which I think will be Safari 14.2. + https://bugs.webkit.org/show_bug.cgi?id=218076 +*/ +:target { scroll-margin-top: calc(var(--menu-bar-height) + 0.5em); } diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index f0b50582..649873ac 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -104,12 +104,12 @@ fn check_correct_cross_links_in_nested_dir() { assert_contains_strings( first.join("index.html"), - &[r##"href="#some-section" id="some-section""##], + &[r##"

"##], ); assert_contains_strings( first.join("nested.html"), - &[r##"href="#some-section" id="some-section""##], + &[r##"

"##], ); } @@ -373,7 +373,7 @@ fn able_to_include_files_in_chapters() { let includes = temp.path().join("book/first/includes.html"); let summary_strings = &[ - r##"

Summary

"##, + r##"

Summary

"##, ">First Chapter", ]; assert_contains_strings(&includes, summary_strings);